WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] query_posts ordering issue

[Resolved] query_posts ordering issue

  • Pulling my hair out trying to get these thumbnails to display in the latest order ‘newest first’ – Have tried various different permutations but still the thumbnails display as ‘oldest first’.

    <div class="container">
    <?php if ( have_posts() ) : ?>
    <?php query_posts(array( 'order'=>'desc', 'orderby'=>'post_date','category__and' => (22), 'showposts' => -1 )); $c = 0;  ?>
    <?php while ( have_posts() ) : the_post(); $c++; ?>
    <div class="four columns"> <a title="<?php the_title(); ?>" href="<?php the_permalink() ?>" style="display:block;">
      <?php
    if(has_post_thumbnail()) {
    	the_post_thumbnail('medium');
    } else {
    	echo '<img src="'.get_bloginfo("template_url").'/images/img-default.png" width="220" height="147" />';
    }
    ?>
      </a> <a title="<?php the_title(); ?>" href="<?php the_permalink() ?>">
      <?php the_title(); ?>
      </a>
      <h6>
        <?php the_field('job_url'); ?>
      </h6>
    </div>
    <?php if( $c == 4) echo '</div><!--container end--><div class="container"><!--container start-->'; elseif ($c == 8) echo '</div><!--container end-->';?>
    <?php if( $c == 8) echo '<div class="container"><!--container start-->'; elseif ($c == 12) echo '</div><!--container end-->';?>
    <?php if( $c == 12) echo '<div class="container"><!--container start-->'; elseif ($c == 16) echo '</div><!--container end-->';?>
    <?php endwhile; endif; ?>
Viewing 8 replies - 1 through 8 (of 8 total)
  • esmi

    @esmi

    Forum Moderator

    Try just using:

    <?php query_posts(array( 'category__and' => (22), 'posts_per_page' => -1 )); $c = 0; ?>

    Still no joy i’m afraid I have tried doing this aswell

    <?php query_posts('cat=-1&orderby=date&order=ASC&showposts=1'); ?>

    esmi

    @esmi

    Forum Moderator

    Posts are listed in date order (newest first) by default then using query_posts(). If that’s not happening, then something else on the page is interfering with the query. Another Loop perhaps?

    no other loops on the page, thats why im getting so frustrated and am also using the latest version of WP – Really strange as the order does keep changing intermittently although never into the latest post order i require….back to the drawing board perhaps…maybe i will look at using get_posts instead

    esmi

    @esmi

    Forum Moderator

    Are you amending the query for the main Loop? Or this for a secondary Loop?

    ive nailed it…had a conflicting plugin installed called ‘Custom Page Order’ this was affecting the order of the posts. THanks for your help 🙂

    esmi

    @esmi

    Forum Moderator

    Glad to hear that you managed to sort it 🙂

    feel very stupid…schoolboy error!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Resolved] query_posts ordering issue’ is closed to new replies.
Skip to toolbar