<? php $cat = '2'; // Classification ID //Get subcategories to exclude subcategorized articles $args = array( 'parent' => $cat ); $categories = get_categories( $args ); $excludecat = array(); foreach ( $categories as $category ) { $excludecat[] = $category->cat_ID; } $args = array( 'cat'=>$cat,//Classification ID 'posts_per_page'=>'10',//Display the number of articles 'ignore_sticky_posts'=>true,//Exclude top 'category__not_in'=>$excludecat,//Exclude sub category articles 'date_query' => array( array( //Start Date 'after' => array( 'year' => '2022', 'month' => '12', 'day' => '1', ), //End Date 'before' => array( 'year' => '2023', 'month' => '12', 'day' => '31', ), 'inclusive'=>true,//including the current day ), ), ); $query = new WP_Query( $args ); ?> <ul> <? php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();?> <li> <a href="<?php the_permalink(); ?>" rel="bookmark"><? php the_title(); ?></ a> </li> <? php endwhile;?> <? php wp_reset_postdata(); ?> <? php else : ?> <li> No article </li> <? php endif;?> </ul>
'category__not_in' => $excludecat,