Make WordPress Core

Opened 12 years ago

Closed 11 years ago

#2861 closed enhancement (fixed)

Added filter to process custom tag fields

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


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 @@
 			$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.


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':
			return '<li><a href="?pp_album=main&amp;pp_cat=' . intval($args[0]) . '&amp;pp_image=' . intval($args[1]). '">' . __('Photo','photopress') . '</a></li>';
			return $custom_tag;


Attachments (2)

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

Download all attachments as: .zip

Change History (5)

12 years ago


#1 @mdawaffe
12 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
11 years ago

  • Milestone changed from 2.1 to 2.2

#3 @rob1n
11 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.