Make WordPress Core

Opened 18 years ago

Closed 17 years ago

#2861 closed enhancement (fixed)

Added filter to process custom tag fields

Reported by: devasatyam's profile DevaSatyam Owned by: mdawaffe's profile mdawaffe
Milestone: 2.2 Priority: normal
Severity: minor Version:
Component: General Keywords:
Focuses: Cc:

Description

I added a picture gallery to WP and wanted to be able to add to my posts a reference to the related picture category. I figured that adding custom tags to the post would be the best way to do it. Then, I needed them processed so I added a filter to the the_meta() function.

I followed the instructions on how to add a patch, but right now, I don't see a way to attach the patch, so here it goes in source form:

Index: wp-includes/post-template.php
===================================================================
--- wp-includes/post-template.php	(revision 3923)
+++ wp-includes/post-template.php	(working copy)
@@ -212,7 +212,7 @@
 				continue;
 			$values = array_map('trim', get_post_custom_values($key));
 			$value = implode($values,', ');
-			echo "<li><span class='post-meta-key'>$key:</span> $value</li>\n";
+			echo apply_filters('custom_tags',"<li><span class='post-meta-key'>$key:</span> $value</li>\n",$key,$value);
 		}
 		echo "</ul>\n";
 	}

As for how it is used, this is the code that I added to my picture gallery. I used Photopress as the basis for my gallery, but I modified it so the code as shown is unusable with the original distribution, it is just an example.

add_filter('custom_tags','photopress_custom_tags_process',10,3);

function photopress_custom_tags_process($custom_tag,$key,$value) {
	// sample: <li><span class='post-meta-key'>$key:</span> $value</li>\n
	switch($key) {
		case 'photopress_cat':
			return '<li><a href="?pp_album=main&amp;pp_cat=' . intval($value) . '">' . __('Photos','photopress') . '</a></li>';
		case 'photopress_image':
			$args=explode(',',$value);
			return '<li><a href="?pp_album=main&amp;pp_cat=' . intval($args[0]) . '&amp;pp_image=' . intval($args[1]). '">' . __('Photo','photopress') . '</a></li>';
		default:
			return $custom_tag;
	}
}

Satyam

Attachments (2)

Custom_tags_filter.patch (554 bytes) - added by DevaSatyam 18 years ago.
2861.diff (555 bytes) - added by mdawaffe 18 years ago.
the_meta_key

Download all attachments as: .zip

Change History (5)

@mdawaffe
18 years ago

the_meta_key

#1 @mdawaffe
18 years ago

  • Milestone set to 2.1
  • Owner changed from anonymous to mdawaffe
  • Status changed from new to assigned

This is a nice idea. It'd be difficult for multiple plugins to play nice together here. Still, it's pretty convenient.

I attached a similar patch that calls the filter the_meta_key. It's a bit more descriptive (though not perfect).

#2 @matt
17 years ago

  • Milestone changed from 2.1 to 2.2

#3 @rob1n
17 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [5241]) Add the_meta_key filter with $key and $value arguments. Props mdawaffe. fixes #2861

Note: See TracTickets for help on using tickets.