按升序订购自定义帖子档案

问题描述 投票:0回答:2

我正在尝试使我的自定义帖子类型存档页面反转显示顺序,并希望使其成为ASCENDING。这是我的代码:

<?php   

    while ( have_posts() )
    {
        the_post();
?>

   --MY CODE--

<?php } ?>

我试过把query_posts('order = asc');在while循环之前,但是这导致我的循环从常规帖子中绘制,而不是我的自定义帖子类型。

任何帮助,将不胜感激!谢谢

php wordpress custom-post-type
2个回答
0
投票

在这里使用简单的查询。永远不要使用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(); ?>

-1
投票

您需要将您的订单添加到现有查询中。你做的方式覆盖了查询。试试这个:

global $query_string;
query_posts( $query_string.'&order=ASC' );
while( have_posts() ): the_post();
  // rest of your code
endwhile;
© www.soinside.com 2019 - 2024. All rights reserved.