我有一组帖子,这些帖子都是使用自定义分类法分配的一年。 使用查询帖子,我希望能够对这些帖子进行排序,以便首先显示 2012 年的帖子,然后按字母顺序对其余帖子进行排序。
我下面的示例工作正常,它首先显示所有具有匹配元值为 2012 的帖子,然后第二个循环显示除第一个循环中的帖子之外的其他所有内容......
<?php query_posts( array(
'post_type' => 'project',
'meta_key' => 'start_date_year',
'meta_value' => '2012'
));
$ids = array();
?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<p>This is from Loop 1 - <?php the_title(); ?> - <?php the_id(); ?></p>
<?php $ids[]= $post->ID; ?>
<?php endwhile; endif; wp_reset_query(); ?>
<?php query_posts( array(
'post_type' => 'project',
'post__not_in' => $ids
));
?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<p>This is from Loop 2 - <?php the_title(); ?> - <?php the_id(); ?></p>
<?php endwhile; endif; wp_reset_query(); ?>
<?php pagination(); ?>
我现在剩下的唯一问题是分页,它显示 2 页,但每页都包含相同的结果......
我会运行两个循环,从数组中的第一个循环中收集帖子的 ID,并通过将其添加到第二个数组中来将它们从第二个数组中排除wp_query $args
一样...
'post__not_in' => $array_variables_from_first_loop,