This is my category.php. I want to filter some posts from this category. Posts were posted in parent and child categories. Show only posts from this category and not from child categries. "category__not_in" not working when argument given as variable. If I use
'category__not_in'=> array(20,22,23,24)
like this it works perfectly.. In below code 'category__not_in'=> array($sub_cat_ids)
not works. please help
<?php
$current_cat_id = get_cat_id( single_cat_title("",false) );
$catlist = get_categories('hide_empty=0&child_of='.$current_cat_id.'&depth=10&parent='.$current_cat_id );
$sub_cat_ids = "";
foreach($catlist as $cat){
$sub_cat_ids = $cat->cat_ID.",".$sub_cat_ids;
}
if(!empty($catlist)){ ?>
<ul class="insight_style">
<?php
$i=1;
$args = array(
'post_type' => 'post',
'posts_per_page' => -1,
'category__not_in'=> array($sub_cat_ids),// not working
'category__in' => $current_cat_id,
'paged' => $paged
);
$page_query = new WP_Query($args);
if ( $page_query->have_posts() ) : while ($page_query->have_posts()) : $page_query->the_post();
} ?>
<li>
// do some stuff
</li>
<?php $i++; endwhile; endif; wp_reset_query(); ?>
</ul>
<?php } ?>