I have custom post type with some products. I need to add some content filtering now. I have custom meta box with "author". I want to add buttons with authors that will act like categories. So let me explain it by example: I have 3 products: (product num - author)

1 - John
2 - Sarah
3 - Tom

When I go to my page I see all three products. I want to add 3 buttons on top:

John| Sarah | Tom

Every click on button filters results of my query. So by clicking John we see only one product on my site - product 1. How to bite this?

I've displayed text with authors using another query_posts() above my original query, but I have no idea what to do next?

2 Answers 2


You can filter your query_posts() results by a custom meta field with the "meta_query" array and its corresponding subfilters. For more information check the Wordpress codex on Custom Field Parameters.


An alternative method would be to setup the new filter variables in Wordpress' query_vars and use that instead of $_GET:


  • Thanks for the link. So You think that simply using php for adding clicked values to the link and $_GET is a good way of doing this?
    – smogg
    Commented Mar 19, 2012 at 20:58
  • As long as the variables are properly escaped and filtered, there's no reason not to use this method, as it is the simplest way in PHP to handle a form that filters content. I've used similar solutions for filtering content in Wordpress. You can also declare new variables in the "query_vars" and use that instead, Wordpress has information in its codex: codex.wordpress.org/Custom_Queries#Custom_Archives
    – Dave Hunt
    Commented Mar 21, 2012 at 15:42

Something like this maybe ?

$query = new WP_Query( array( 'meta_key' => 'author', 'meta_value' => 'john' ) );
// Loop for John ...

$query = new WP_Query( array( 'meta_key' => 'author', 'meta_value' => 'sarah' ) );
// Loop for Sarah ...

you could separate them with maybe a switch statement.

Probably you will need to pay careful attention to resetting the query, there are three ways to do it. Good post on SE here somewhere explaining the difference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.