Filtering Custom Post Type admin panel by custom meta data
I use some custom meta data in a Custom Post Type, and I display some meta fields in the admin UI.
Is there a way to add filtering for these columns?
Let’s say, that for categories or tags there is an option to filter the posts shown in the admin UI edit page, but could I filter by some meta data?
I’m not sure I understand what you want to do, but if it’s what I think you are asking, this article may help (scroll to step 4):
@coopersita thanks for your link, but it is not what I am looking for. I know and also implemented all of these before.
I’ll try to explain again.
Let’s say I have a post type named ‘courses’, and for this post type I have a meta field which is the ‘course status’ and its value can be on or off.
On the admin page that shows the list of all courses I put in the UI the field of the course status.
But let’s say I want now to filter and view only the courses with status ‘on’ or only courses with status ‘off’.
If it is a category, there is the select box that can be used to filter and view only certain categories, but how can I add some filters to custom meta fields?
I hope I am more clear now and that someone has a clue how to achieve this..
You should check out this plugin: http://lud.icro.us/wp-plugins/posts-meta-search.phps
Not made by me but I use it and works perfect.
@ryan_b Thanks a lot for the code!
This is a good basis I can develop from.
I don’t really need to have in the filter select box all the custom
fields that are defined in the db.
Truth is that I tried to manually add the GET parameters meta_key & meta_value to the url, but it didn’t work.
Another interesting issue, do you think there’s a chance to filter by 2 different mata_keys & values?
For example, I put my needed meta_key name as a hidden input field, and my select box is for values that in the meta_values for this key.
Now, If I will add another one, is it possibe to have url such as – domain.com./…..&meta_key=aaa&meta_value=value_aaa&meta_key=bbb&meta_value=value_bbb
I afraid it’s not optional, so if not, how can double filtering by more than one meta keys can be done? I have no idea for this possibility right now…
@maorb: with the plugin suggested by Ryan_B, the parameters to use is ‘mk’ instead of ‘meta_key, and ‘mv’ instead of ‘meta_value’
@bedex78 : Thanks, I know that, I read the code and changed it to have ‘mk’ as hidden input field with the ‘meta_key’ I needed and the ‘mv’ is now for me a select box of the values for that key, I changed the code and the mySQL query to handle this.
But what I wondered was, that before using the plugin, I tried to add to the url itself the ‘meta_key’ and ‘meta_value’ GET parameters, to check if it’s possible at all to filter by them. Somehow that didn’t work and that was strange. Maybe it is a must to hook through the ‘restrict_manage_posts’ filter and add the values to the ‘request’ filter?
That is just interesting to know, but using the code and changing it worked fine.
- The topic ‘Filtering Custom Post Type admin panel by custom meta data’ is closed to new replies.