filter post by date selected in a dropdown in realtime

How to filter custom post type by selected month and year in a dropdown, do i have to make rewrite rules? or javascipt function?

$data_args = array(
‘post_type’=>’news-list’,
‘order’=>’desc’,
‘posts_per_page’ => -1
);

$dataQuery = new WP_Query( $data_args );

$accContent = [];

if($dataQuery -> have_posts()):
while($dataQuery -> have_posts()): $dataQuery->the_post();
$newArr = true;
$id = get_the_id();
$month = get_the_date(‘F’);
$year = get_the_date(‘Y’);
$monthnum = get_the_date(‘m’);

if(array_key_exists($year,$accContent)){
if(array_key_exists($month,$accContent[$year]))
{
array_push($accContent[$year][$month],$id);
$newArr = false;
}
}

if($newArr){
$accContent[$year][$month] = array($id);
}

endwhile;
endif;

Read more here:: filter post by date selected in a dropdown in realtime

Leave a Reply

Your email address will not be published. Required fields are marked *