管理部分中的自定义帖子类型分页问题

时间:2014-10-07 作者:Joe

我有几种自定义帖子类型,下面是其中两种类型的创建:

项目

add_action( \'init\', \'register_cpt_project\' );

function register_cpt_project() {

$labels = array( 
    \'name\' => _x( \'Projects\', \'project\' ),
    \'singular_name\' => _x( \'Project\', \'project\' ),
    \'add_new\' => _x( \'Add New\', \'project\' ),
    \'add_new_item\' => _x( \'Add New Project\', \'project\' ),
    \'edit_item\' => _x( \'Edit Project\', \'project\' ),
    \'new_item\' => _x( \'New Project\', \'project\' ),
    \'view_item\' => _x( \'View Project\', \'project\' ),
    \'search_items\' => _x( \'Search Projects\', \'project\' ),
    \'not_found\' => _x( \'No projects found\', \'project\' ),
    \'not_found_in_trash\' => _x( \'No projects found in Trash\', \'project\' ),
    \'parent_item_colon\' => _x( \'Parent Project:\', \'project\' ),
    \'menu_name\' => _x( \'Projects\', \'project\' ),
);

$args = array( 
    \'labels\' => $labels,
    \'hierarchical\' => true,

    \'supports\' => array( \'title\', \'editor\', \'excerpt\' ),
    \'taxonomies\' => array( \'project_categories\' ),
    \'public\' => true,
    \'show_ui\' => true,
    \'show_in_menu\' => true,


    \'show_in_nav_menus\' => true,
    \'publicly_queryable\' => true,
    \'exclude_from_search\' => false,
    \'has_archive\' => true,
    \'query_var\' => true,
    \'can_export\' => true,
    \'rewrite\' => array(\'slug\' => \'our-work/%project_categories%\', \'with_front\' => false),
    \'capability_type\' => \'post\'
);

register_post_type( \'project\', $args );
}
领导力

add_action( \'init\', \'register_cpt_leadership\' );
function register_cpt_leadership() {

    $labels = array( 
        \'name\' => _x( \'Leaders\', \'leadership\' ),
        \'singular_name\' => _x( \'Leadership\', \'leadership\' ),
        \'add_new\' => _x( \'Add New\', \'leadership\' ),
        \'add_new_item\' => _x( \'Add New Leadership\', \'leadership\' ),
        \'edit_item\' => _x( \'Edit Leadership\', \'leadership\' ),
        \'new_item\' => _x( \'New Leadership\', \'leadership\' ),
        \'view_item\' => _x( \'View Leadership\', \'leadership\' ),
        \'search_items\' => _x( \'Search Leaders\', \'leadership\' ),
        \'not_found\' => _x( \'No leaders found\', \'leadership\' ),
        \'not_found_in_trash\' => _x( \'No leaders found in Trash\', \'leadership\' ),
        \'parent_item_colon\' => _x( \'Parent Leadership:\', \'leadership\' ),
        \'menu_name\' => _x( \'Leaders\', \'leadership\' ),
    );

    $args = array( 
        \'labels\' => $labels,
        \'hierarchical\' => true,

        \'supports\' => array( \'title\', \'editor\' ),

        \'public\' => true,
        \'show_ui\' => true,
        \'show_in_menu\' => true,
        \'menu_position\' => 20,

        \'show_in_nav_menus\' => true,
        \'publicly_queryable\' => true,
        \'exclude_from_search\' => false,
        \'has_archive\' => false,
        \'query_var\' => true,
        \'can_export\' => true,
        \'rewrite\' => array(\'slug\' => \'who-we-are/leadership\'),
        \'capability_type\' => \'post\'
    );

    register_post_type( \'leadership\', $args );
}
在公共网站上一切都很好,但当你登录到wp管理部分时,事情就变得很奇怪了。

领导岗位类型功能正常。但是,当使用列表页面中的分页按钮时,项目类型在转到任何大于1的页面时不会返回任何帖子。

所以如果我去:http://www.example.com/wp-admin/edit.php?post_type=project&paged=2

我得到:

找不到项目

即使有70篇文章,并且屏幕选项设置为每页20篇文章。是的,我可以将该选项设置为一个更大的数字,并在一个页面中显示所有帖子,但这并不能解决当前的问题。

以前有没有人遇到过这个问题,或者有没有想过如何解决这个问题?

2 个回复
最合适的回答,由SO网友:Joe 整理而成

事实证明,在我的函数中。php文件,我有以下函数:

function limit_posts_per_archive_page() {
    if ( is_tax(\'project_categories\') )
        $limit = 9999;
    else
        $limit = get_option(\'posts_per_page\');
        set_query_var(\'posts_per_archive_page\', $limit);
    }
add_filter(\'pre_get_posts\', \'limit_posts_per_archive_page\');
这是一个修改前端分页的旧函数,结果表明这是导致错误的原因。

删除该函数修复了此问题。

SO网友:Divyesh Tailor

这是Permalinks的问题。请先转到“外观”>“永久链接”>“设置默认值”,然后再设置帖子名称。然后刷新你的帖子,你就可以用标题显示你的帖子内容了。

结束

相关推荐

Pagination custom query

我正在尝试制作一个自定义页面模板,以显示浏览次数最多的帖子。我可以回复帖子,但我很难弄清楚如何分页。以下是我所拥有的:$args = array(\'orderby\' => \'meta_value_num\', \'meta_key\' => \'post_views_count\', \'posts_per_page\' => 36 ); $loop = new WP_Query( $args ); while ( $