So I'm looping with WP_Query and here is my code:
$country_posts = new WP_Query(get_direct_children($continent_cats));
if ($country_posts->have_posts()) : while ($country_posts->have_posts()) : $country_posts->the_post();
the get_direct_children function:
function get_direct_children($cat_name) {
if (gettype($cat_name) == 'string') : $category_id = get_cat_ID($cat_name);
elseif (gettype($cat_name) == 'integer') : $category_id = $cat_name;
endif;
$args = array('parent' => $category_id);
$categories = get_categories($args);
$cats = wp_list_pluck($categories,'cat_ID');
$args = array (
'category__and' => $cats
);
return $args;
}
$country_posts->have_posts() returns true only if 1 category gets returned from get_direct_children. This happens when I turn off all the children of $continent_cats (which is a string by the way) except 1.
When only 1 child category is active:
var_dump(get_direct_children($continent_cats));
returns:
array(1) { ["category__and"]=> array(1) { [0]=> string(2) "72" } }
So yay this is what I want it to do. have_posts() is returning true and looping my 1 active subcategory. HOWEVER, when I enable another child category, have_posts() returns false(I think, it's just not posting any content).
So this same function:
var_dump(get_direct_children($continent_cats));
returns:
array(1) { ["category__and"]=> array(2) { [0]=> string(2) "72" [1]=> string(2) "71" } }
when I have 2 child categories active. Since this looks like correct syntax AND category__and is taking in the correct variable type, why doesn't it loop those 2 categories? Why does it not even loop 1 category?
Thanks