0

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.

1

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);
 }
}
1
  • 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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