I'm developing a custom wp plugin for category loops. I'm trying to get posts that have multiple categories.
For instance, I want to get ONLY the posts that have BOTH categories 1 and 2 - meaning that posts that have categories 1 OR 2 don't appear like so:
[myplugin category="1,2"]
This don't appear to work, as it is displaying posts that have ONLY the first category (1).
Searched and tried a lot of ways to achieve this. My actual plugin code is this:
function pluginHandler($atts, $content = null) {
$cat = empty($atts['category']) ? '0' : $atts['category'];
global $post;
$args = array(
'posts_per_page' => -1,
'category__and' => array($cat)
);
$the_query = new WP_Query($args);
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) :
$the_query->the_post();
...
endwhile;
endif;
}
What am I doing wrong?