我有一个令人头疼的问题!我有许多不同的帖子类型,默认的帖子/页面/附件+使用默认的CPT UI设置创建的少数几种。只有其中一个(文章)行为不端,WP_Query posts_per_page
参数被忽略。
除了上面提到的通常的嫌疑人之外,我找不到任何有关保留后弹的信息。
所以,我们有一堆post_type = 文章。为了测试,我进入了数据库并将其中的3个更改为文章 - 删除 s 。虽然我没有在CPT IU或函数中创建帖子类型,但是WP_Query能够正确地返回它......正确无误!
$a_articles__featured = array (
'post_type' => 'articles',
'nopaging' => false,
'posts_per_page' => 2,
'update_post_term_cache' => false,
'update_post_meta_cache' => false
);
$q_articles__featured = new WP_Query( $a_articles__featured );
^^^返回所有帖子,其中包含文章的CPTUI post_type
$a_articles__featured = array (
'post_type' => 'article',
'nopaging' => false,
'posts_per_page' => 2,
'update_post_term_cache' => false,
'update_post_meta_cache' => false
);
$q_articles__featured = new WP_Query( $a_articles__featured );
^^^使用手动调整的文章
的post_type返回2个帖子 $a_articles__featured = array (
'post_type' => 'page',
'nopaging' => false,
'posts_per_page' => 2,
'update_post_term_cache' => false,
'update_post_meta_cache' => false
);
$q_articles__featured = new WP_Query( $a_articles__featured );
^^^返回2个帖子,其默认post_type为 page
$a_articles__featured = array (
'post_type' => 'events',
'nopaging' => false,
'posts_per_page' => 2,
'update_post_term_cache' => false,
'update_post_meta_cache' => false
);
$q_articles__featured = new WP_Query( $a_articles__featured );
^^^返回2个帖子,其中包含事件的CPTUI post_type
除了使用文章,这是网址中断,有人可以建议从这里解决问题吗?
谢谢!
答案 0 :(得分:0)
更新:我删除了CPT UI并采用了功能方法。惊喜,它就像一个魅力。
function custom_post_type_articles() {
$labels = array(
'name' => _x( 'Articles', 'Post Type General Name', 'cyprusprofile' ),
'singular_name' => _x( 'Article', 'Post Type Singular Name', 'cyprusprofile' ),
'menu_name' => __( 'Articles', 'cyprusprofile' ),
'parent_item_colon' => __( 'Parent Article', 'cyprusprofile' ),
'all_items' => __( 'All Articles', 'cyprusprofile' ),
'view_item' => __( 'View Article', 'cyprusprofile' ),
'add_new_item' => __( 'Add New Article', 'cyprusprofile' ),
'add_new' => __( 'Add New', 'cyprusprofile' ),
'edit_item' => __( 'Edit Article', 'cyprusprofile' ),
'update_item' => __( 'Update Article', 'cyprusprofile' ),
'search_items' => __( 'Search Article', 'cyprusprofile' ),
'not_found' => __( 'Not Found', 'cyprusprofile' ),
'not_found_in_trash' => __( 'Not found in Trash', 'cyprusprofile' ),
);
$args = array(
'label' => __( 'articles', 'cyprusprofile' ),
'description' => __( 'Articles', 'cyprusprofile' ),
'labels' => $labels,
// Features this CPT supports in Post Editor
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
// You can associate this CPT with a taxonomy or custom taxonomy.
// 'taxonomies' => array( 'genres' ),
/* A hierarchical CPT is like Pages and can have
* Parent and child items. A non-hierarchical CPT
* is like Posts.
*/
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
// 'menu_position' => 5,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
// Registering your Custom Post Type
register_post_type( 'articles', $args );
}