سؤال

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