I'm trying to make my custom post type archive page reverse the display order, and want to make it ASCENDING. This is my code:

<?php   

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

   --MY CODE--

<?php } ?>

I tried putting query_posts('order=asc'); before the while loop, but this caused my loop to draw from the regular posts, not my custom post type.

Any help would be appreciated! Thanks

有帮助吗?

解决方案

Use a simple query here. Don't use query_posts, never ever. Use WP_Query. You should do

<?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(); ?>

其他提示

You need to add your ordering to the existing query. The way you did it overwrote the query. Try this:

global $query_string;
query_posts( $query_string.'&order=ASC' );
while( have_posts() ): the_post();
  // rest of your code
endwhile;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top