我有几个不同的CPT设置;\'作业、事件、产品。它们显示在网站的各个页面上,在侧边栏或页脚区域。
使用以下代码,我的CPT获得输出,但除了“post\\u type”之外,所有$参数都被忽略。输出帖子时,就像“每页帖子数”=>-1.
如果我将“post\\u type”留空,则会加载博客帖子,并且所有参数都会按预期工作。
无论我将哪个CPT用于“post\\u type”,我都会遇到同样的问题。以下“工作”示例:
<?php
$args = array(
\'post_type\' => \'jobs\',
\'posts_per_page\' => 3,
\'post_status\' => \'publish\',
\'order\' => \'DESC\',
\'orderby\' => \'menu_order\'
);
$wp_query = new WP_Query($args);
while ( $wp_query->have_posts() ) : $wp_query->the_post();
?>
// POST CONTENT
<?php endwhile; wp_reset_query(); ?>
CTP的设置如下:
add_action( \'init\', \'m_jobs_init\' );
function m_jobs_init() {
$labels = array(
\'name\' => __( \'Jobs\' ),
\'singular_name\' => __( \'Job\' ),
\'menu_name\' => __( \'Jobs\' ),
\'name_admin_bar\' => __( \'Jobs\' ),
\'add_new\' => __( \'Add Job\' ),
\'add_new_item\' => __( \'Add New Job\' ),
\'new_item\' => __( \'New Job\' ),
\'edit_item\' => __( \'Edit Job\' ),
\'view_item\' => __( \'View Job\' ),
\'all_items\' => __( \'All Jobs\' ),
\'search_items\' => __( \'Search Jobs\' ),
\'parent_item_colon\' => __( \'Parent Job\' ),
\'not_found\' => __( \'No Jobs Found\' ),
\'not_found_in_trash\' => __( \'No Jobs Found in Trash\' ),
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_in_nav_menus\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'jobs\' ),
\'capability_type\' => \'post\',
\'has_archive\' => true,
\'hierarchical\' => true,
\'menu_position\' => null,
\'supports\' => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'excerpt\', \'page-attributes\',\'post-formats\' )
);
register_post_type( \'jobs\', $args );
}
其他注释如下:
我有一个pre\\u get\\u posts过滤器,可以更改归档页面上的输出。我尝试删除它,但此查询没有任何更改。
我还检查了所有其他wp\\u查询循环是否正在使用wp\\u reset\\u postdata()关闭;但无济于事。
我还运行了var\\u dump($wp\\u query);我可以看到它看起来不太正确,但不确定错误是从哪里来的。截断的版本为:
object(WP_Query)[8153]
public \'query\' =>
array (size=5)
\'post_type\' => string \'jobs\' (length=4)
\'posts_per_page\' => int 3
\'post_status\' => string \'publish\' (length=7)
\'order\' => string \'DESC\' (length=4)
\'paged\' => int 1
public \'query_vars\' =>
array (size=65)
\'post_type\' => string \'jobs\' (length=4)
\'posts_per_page\' => int -1
\'post_status\' => string \'publish\' (length=7)
\'order\' => string \'ASC\' (length=3)
\'paged\' => int 1
第二个数据块来自哪里?这有
\'posts_per_page\' => int -1
和
\'order\' => string \'ASC\'
这可能是问题的原因。