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 need to search for posts that belong to multiple categories, but they must match all categories listed, as in if I list category names 'japanese' and 'dessert' the matching posts need to be in both the 'japanese' and 'dessert categories.

Is there something like category__and for category names? I am using a wordpress multi instance and my category ID numbers vary between my test and production environments, hence I cannot use category__and.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Well... you could grab category names ID using get_the_category function(Wordpress Codex).

$names = {"japanese", "dessert"};
$categories = get_the_category();
if($categories){
 foreach($categories as $category){
  if( in_array($category->cat_name, $names) ) array_push($ids, $category->term_id);
 }
}
share|improve this answer
    
That was basically what I did. I got the ID #'s with a query and then used category__and with an array of variables –  Purcell Nov 13 '13 at 23:52

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.