WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

it's a catalog website for different product. I need a function that will get the category of the selected product, and get all the product from that category

Let see an example. A table, is in wood category and kitchen. So when display table, under the table i like all the other kitchen product listed as well as all the other wood product... it good for cross selling !...

how do i do that ?

share|improve this question
up vote 2 down vote accepted

You can use WP_Query's tax_query to do this. You would want the args (just on the tax_query, I'll leave the rest up to you, you have the documentation) to look something like this:

'tax_query' => array(
    'relation' => 'OR'
        'taxonomy' => 'category',
        'field'    => 'slug',
        'terms'    => 'wood'
        'taxonomy' => 'category',
        'field'    => 'slug',
        'terms'    => 'kitchen'

That method will allow you to query as many types of posts as you like. Alternatively, you can have multiple WP_Querys and use wp_get_post_categories() to get the terms for a foreach to feed dynamically generated suggestions, each with its own WP_Query. It sorta depends how you want the output to look.

share|improve this answer
I will prefer to do a request, get all product that are wood and kitchen into an array, then add all the kitchen to this array, then all the wood to this array, the single out all the array, and get it to screen ! – menardmam Feb 27 '12 at 22:15
That would require multiple WP_Querys...is this question solved? – mor7ifer Feb 27 '12 at 22:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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