为什么第2页不能在wp查询中工作

时间:2017-04-02 07:01:58

标签: php wordpress

为什么http://localhost/wp/?paged=2及更老版本在wp_query中无效?

我有超过15个帖子的“自定义帖子类型”的电影和系列。 它在前端分为2页,但是当我按下旧帖子时,页面仍然是第一页。

这是我的index.php循环代码:

{{1}}

1 个答案:

答案 0 :(得分:0)

我找到了解决方案:

    add_filter( 'pre_get_posts', 'my_get_posts' );

    function my_get_posts( $query ) {

        if ( $query->is_main_query() &&  is_home()  ) {
            $query->set( 'post_type', array( 'post', 'movie', 'series' ) );
        }
        if ( $query->is_main_query() &&  is_category()  ) {
            $query->set( 'post_type', array( 'post', 'movie', 'series' ) );
        }
        if ( $query->is_main_query() &&  is_search()  ) {
            $query->set( 'post_type', array( 'post', 'movie', 'series' ) );
        }
        if ( $query->is_main_query() &&  is_tag()  ) {
            $query->set( 'post_type', array( 'post', 'movie', 'series' ) );
        }
        return $query;
    }

此代码不会停止显示导航菜单

相关问题