我有一个查询的结果,它们很好,我通过标签获得帖子。我想在WHILE循环中对结果进行排序。这是密码
$tags = wp_get_post_tags($post->ID);
if ($tags) {
$first_tag = $tags[1]->term_id;
$args=array(
\'tag__in\' => array($first_tag),
// \'post__not_in\' => array($post->ID),
\'caller_get_posts\'=>1,
\'posts_per_page\' =>100,
\'post_type\'=>\'episode\',
\'orderby\' => \'post_title\',
\'order\' => \'ASC\'
);
$my_query = new WP_Query($args);
if ( $my_query->have_posts() ){
$s = 0;
while ( $my_query->have_posts() ) : $my_query->the_post();
$original_title = get_the_title();
list($a, $b) = explode(\' Season \', $original_title);
$exp_count = explode(\' Season \', $original_title);
$c = substr("$b",0,2).\'<br>\';
echo \'Season \'.$c;
echo get_the_title() . \'<br>\';
endwhile;
}
wp_reset_query();
}
这是输出
我想把第三季和第四季分别排序如下:
SO网友:Shibi
我可能会这样做,使它充满活力,但这与标题有一些问题,必须是“第n季”的标题。
更好的解决方案可能是添加一些带有季节的自定义字段,或者添加一些自定义分类法来进行筛选。
if ( $my_query->have_posts() ){
$seasons = array();
foreach($my_query->posts as $mypost) {
preg_match(\'/Season (\\d*)/\', $mypost->post_title, $season);
$seasons[$season[1]][] = $mypost;
}
// and then you could use seasons array
}