Internal redirect from page to category

admin2025-06-06  3

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.

Share Improve this question asked Oct 31, 2018 at 17:19 Javier MarínJavier Marín 1011 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

I 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;
    }
);
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749216873a317341.html

最新回复(0)