WordPress.org

Ready to get started?Download WordPress

Forums

Filtering Custom Post Type admin panel by custom meta data (9 posts)

  1. maorb
    Member
    Posted 3 years ago #

    Hi,

    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?

    Thanks

  2. coopersita
    Member
    Posted 3 years ago #

    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):
    http://thinkvitamin.com/dev/create-your-first-wordpress-custom-post-type/

  3. maorb
    Member
    Posted 3 years ago #

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

    Thanks

  4. maorb
    Member
    Posted 3 years ago #

    Any new ideas about that?

    Thanks

  5. Ryan_B
    Member
    Posted 3 years ago #

    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.

  6. maorb
    Member
    Posted 3 years ago #

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

  7. maorb
    Member
    Posted 3 years ago #

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

  8. Aldi
    Member
    Posted 3 years ago #

    @maorb: with the plugin suggested by Ryan_B, the parameters to use is 'mk' instead of 'meta_key, and 'mv' instead of 'meta_value'

  9. maorb
    Member
    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic