我如何得到自定义帖子类型显示在存档页面没有打破我的自定义字段下面?



我已经在我的functions.php文件中添加了以下代码,但是一旦我添加了它,它似乎打破了它下面的所有ACF自定义字段(一些字段在页脚)。

是否有办法解决这个问题,使其停止发生?

add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if( is_category() ) {
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else
$post_type = array('nav_menu_item', 'post', 'conditions', 'product-reviews', 'conversations', 'experts', 'custom_fields'); 
$query->set('post_type', $post_type);
return $query;
} 
}

我可以通过修改我的代码来解决这个问题:

function custom_post_type_cat_filter($query) {
if ( !is_admin() && $query->is_main_query() ) {
if ($query->is_category()) {
$query->set( 'post_type', array( 'post', 'conditions', 'product-reviews', 'conversations' ) );
}
}
}
add_action('pre_get_posts','custom_post_type_cat_filter');

最新更新