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.

I have made a multiple category. Each item belong to one or more category. So when display one item, i like to retreive the category of this item, and display all post that have belong to that category.

Example. Chair : cat = sit, leather, one person

So when display the chair, i like below to display all item that have : sit leather and one person as category

Is there a plugsin that do that ?, or in php it's simple to do ?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted
# according to your example:
$categories = array ( 'sit', 'leather', 'one person'  );

# get all id's by the category names
foreach ($categories as $category_name) {
$category = get_term_by( 'name', $category_name , 'category' ); 
$ids[] = $category->term_id;
}

# get all posts for the categories
query_posts( 'cat='.join(',',$ids) );

Sorry, I cannot test it right now, this is just a guess till tomorrow.

share|improve this answer
    
And I think using $categories = get_the_category(); in the first line would get the categories of the post, if you want to do it that way –  Rev. Voodoo Apr 1 '11 at 13:15
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.