WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] query_posts ordering issue (9 posts)

  1. jason.wintermeyer
    Member
    Posted 1 year ago #

    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; ?>
  2. esmi
    Forum Moderator
    Posted 1 year ago #

    Try just using:

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

  3. jason.wintermeyer
    Member
    Posted 1 year ago #

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

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

  4. esmi
    Forum Moderator
    Posted 1 year ago #

    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?

  5. jason.wintermeyer
    Member
    Posted 1 year ago #

    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

  6. esmi
    Forum Moderator
    Posted 1 year ago #

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

  7. jason.wintermeyer
    Member
    Posted 1 year ago #

    ive nailed it...had a conflicting plugin installed called 'Custom Page Order' this was affecting the order of the posts. THanks for your help :-)

  8. esmi
    Forum Moderator
    Posted 1 year ago #

    Glad to hear that you managed to sort it :-)

  9. jason.wintermeyer
    Member
    Posted 1 year ago #

    feel very stupid...schoolboy error!

Topic Closed

This topic has been closed to new replies.

About this Topic