I’ve added tags to all Media items with this code:
function wptp_add_tags_to_attachments() {
register_taxonomy_for_object_type( 'post_tag', 'attachment' );
}
add_action( 'init' , 'wptp_add_tags_to_attachments' );
It works great expect one thing. If I search for a media file in the Admin Media Library it does not work with tags.
How can I get the Admin Media Library to include the tags in the search?
You can do this using WordPress action hooks. You need to update the WordPress default search query when searching attachments using hooks posts_where, posts_join and posts_groupby.
Please add below to your themes functions.php
What these functions does is:
custom_attachments_join
functions joinsterm_relationships
andterm_taxonomy
for giving us ability to search for tagscustom_attachments_where
function modifies the WordPress default where condition to include our search terms to search fortaxonomy
orterms
fieldscustom_attachments_groupby
adds group by condition to remove duplicate posts if any.These functions also check whether we are searching for attachment and if we are performing the search in the WordPress admin area.
Please check with this links for more reference on the hooks I have used.
Hope this helps you
This plugin’s changelog page says that it searches media tags added by its program:
http://wordpress.org/plugins/media-tags/changelog/
If you’re building your own plugin, I recommend grabbing their code and seeing what they’re doing. Otherwise, their plugin seems to be exactly what you’re looking for.
Unfortunately Sabari’s solution doesn’t work for the search-form in the “Add Media” – section.
I am using the following function in my functions.php (code based on the “Media Search Enhanced” plugin by Yoren Chang):
The solution benedikt works fine, but the language filter is with the wpml plugin.
I use Polylang and looking for the right way to do the same filter, I can not find a solution even with the Polylang documentation…
There is just this part to change :
by something like that :
If someone can help ?