Select posts that match multiple category names, must match all categories listed

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.

Solutions Collecting From Web of "Select posts that match multiple category names, must match all categories listed"

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