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

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
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();
 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


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.