wordpress-排序多个帖子类型
我试图在一个页面中订购多个帖子类型 我下面的解决方案是可行的,但帖子并没有准确地按类型显示wordpress-排序多个帖子类型,wordpress,sorting,custom-type,Wordpress,Sorting,Custom Type,我试图在一个页面中订购多个帖子类型 我下面的解决方案是可行的,但帖子并没有准确地按类型显示 <?php $args = array_merge( $wp_query->query, array( 'post_type' =>array( 'editorial','video','portfolio' ),'posts_per_page=-1','orderby'=>'post_type') );
<?php $args = array_merge( $wp_query->query,
array( 'post_type' =>array( 'editorial','video','portfolio' ),'posts_per_page=-1','orderby'=>'post_type') );
}
query_posts( $args );
$postType='';
if (have_posts()) : while (have_posts()) : the_post();
$PT = get_post_type( $post->ID );
if($postType != $PT){
$postType = $PT;
echo '<p class="clearfix"><h1>All posts of type : '.$postType.'</h1></p>';
}
?>
<?php
if($postType == 'editorial'){ ?>
<?php echo $postType; ?>
<?php }elseif($postType == 'video'){ ?>
<?php echo $postType; ?>
<?php }elseif($postType == 'portfolio'){
<?php echo $postType; ?>
}
?>
}
?>
它的输出是这样的:
所有类型的职位:编辑
社论
社论
社论
所有帖子类型:视频
录像带
录像带
所有类型的帖子:编辑//问题
社论
所有职位类别:公文包
投资组合
投资组合
投资组合
投资组合
提前感谢根据,post\u type
不是orderby
参数允许的值之一
解决问题的一种方法是使用
function order_posts_by_type($original_orderby_statement) {
global $wpdb;
return $wpdb->posts .".post_type ASC";
}
add_filter('posts_orderby', 'order_posts_by_type');
$custom_query = new WP_Query( array(
'post_type' =>array( 'editorial','video','portfolio' ),
'posts_per_page' => '-1',
'orderby'=>'post_type',
'order' => 'ASC'
) );
remove_filter('posts_orderby', 'order_posts_by_type');
FWIW,我建议将
'posts\u per\u page=-1'
更改为'posts\u per\u page'=>-1
,以与您的其他参数保持一致。没问题;如果有帮助,请随意接受答案和/或投赞成票。这是在这里表达感激的最好方式;-)