Opened 7 years ago
Closed 6 years ago
#2861 closed enhancement (fixed)
Added filter to process custom tag fields
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 2.2 |
| Component: | General | Version: | |
| Severity: | minor | Keywords: | |
| 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&pp_cat=' . intval($value) . '">' . __('Photos','photopress') . '</a></li>';
case 'photopress_image':
$args=explode(',',$value);
return '<li><a href="?pp_album=main&pp_cat=' . intval($args[0]) . '&pp_image=' . intval($args[1]). '">' . __('Photo','photopress') . '</a></li>';
default:
return $custom_tag;
}
}
Satyam
Attachments (2)
Change History (5)
DevaSatyam — 7 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).

the_meta_key