我正在尝试使我的自定义帖子类型存档页面反转显示顺序,并希望使其成为ASCENDING。这是我的代码:
<?php
while ( have_posts() )
{
the_post();
?>
--MY CODE--
<?php } ?>
我试过把query_posts('order = asc');在while循环之前,但是这导致我的循环从常规帖子中绘制,而不是我的自定义帖子类型。
任何帮助,将不胜感激!谢谢
在这里使用简单的查询。永远不要使用query_posts
。使用WP_Query
。你应该做
<?php
$args= array(
'order' => 'ASC',
'post_type' => 'NAME OF YOUR CPT'
);
$the_query = new WP_Query( $args );
?>
<?php while ( $the_query->have_posts() ) :$the_querythe_post(); ?>
您需要将您的订单添加到现有查询中。你做的方式覆盖了查询。试试这个:
global $query_string;
query_posts( $query_string.'&order=ASC' );
while( have_posts() ): the_post();
// rest of your code
endwhile;