I want to implement a page, let's say /today-deals
that will show all posts under today category, like if we were navigating to /category/deals-for-october-31-2018
but without changing the URL.
I want to implement a page, let's say /today-deals
that will show all posts under today category, like if we were navigating to /category/deals-for-october-31-2018
but without changing the URL.
1 Answer
Reset to default 0I achieved it using template_include
hook:
add_filter(
'template_include',
function ($template) {
if (is_page('today-deals')) {
global $wp_query;
$wp_query = new WP_Query( array( 'category_name' => date('Ymd') ) );
$template = 'category.php';
}
return $template;
}
);