Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

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'
    array(
        'taxonomy' => 'category',
        'field'    => 'slug',
        'terms'    => 'wood'
    ),
    array(
        '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? –  m0r7if3r Feb 27 '12 at 22:24
add comment

Your Answer

 
discard

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.