admin管理员组

文章数量:1130349

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;
    }
);

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;
    }
);

本文标签: Internal redirect from page to category