logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$10
query_posts orderby not working

Hi

Am tearing my hair out with this one, i simply wish to order my posts by date or anyway really, just some way of putting them into an order. I can not work out how it is ordering them at the moment as it seems totally random.

If I create a post called Test it will chuck it in the middle of the list which doesn't fit for date or alphabetically.

Here is the code:


<div class="item">

<?php query_posts("cat=19&posts_per_page=5&orderby=date"); ?>

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

<div class="grid_2 fit5">

<a href="<?php the_permalink(); ?>">

<?php if($ts_blogimage != 'No'): ?>

<?php if(get_images() != ''){ ?>
<img src="<?php bloginfo('template_directory'); ?>/tools/thumb.php?src=<?php echo get_post_meta($post->ID, 'front_thumb', true); ?>&amp;w=170&amp;h=120&amp;zc=1&amp;q=100" alt="<?php the_title(); ?>" />
<?php }else{ ?>
<img src="<?php bloginfo('template_directory'); ?>/tools/thumb.php?src=<?php echo get_post_meta($post->ID, 'front_thumb', true); ?>&amp;w=170&amp;h=120&amp;zc=1&amp;q=100" alt="<?php the_title(); ?>" />
<?php } ?>

<?php endif; ?>

<span><?php the_title(); ?></span>

</a>
<?php the_content('Read more...'); ?>

</div><!--grid3-->

<?php endwhile; else: ?>

<?php endif; ?>



</div><!--item-->



Many thanks!
Jen

This question has been answered.

Jennie Routley | 01/16/12 at 6:13am Edit


(8) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    01/16/12
    6:16am
    Julio Potier says:

    hello

    Before your "query_posts" try to add "wp_reset_query();"

    See you soon !

    Previous versions of this answer: 01/16/12 at 6:16am

    • 01/16/12 6:49am

      Jennie Routley says:

      Thank you! I think this was part of the problem as another query was being run above it. It still would not work for me though so I remade all the posts and then it did, god knows what it was, some bug in the original posts which were made ages ago.

      I tried changing the publish dates but it did not recognise them as being changed.

      Thanks though this suggestion was the one I was looking for!

  • avatar
    Last edited:
    01/16/12
    6:18am
    Francisco Javier Carazo Gil says:

    Hi,

    Try also to set the order type ASC or DESC:


    <?php query_posts('orderby=title&order=ASC'); ?>


    • 01/16/12 6:20am

      Francisco Javier Carazo Gil says:

      In your case:


      <?php query_posts("cat=19&posts_per_page=5&orderby=post_date&order=ASC"); ?>


      And remember is "post_date" no "date".

  • avatar
    Last edited:
    01/16/12
    6:19am

    This answer was downvoted by the top experts.

  • avatar
    Last edited:
    01/16/12
    6:19am
    Jens Filipsson says:

    Hey!
    Try changing:

    <?php query_posts("cat=19&posts_per_page=5&orderby=date"); ?>


    To:

    <?php query_posts("cat=19&posts_per_page=5&orderby=date&order=ASC"); ?>

  • avatar
    Last edited:
    01/16/12
    6:20am
    Arnav Joy says:

    try this

    <?php
    wp_reset_query();
    query_posts("cat=19&posts_per_page=5&orderby=date&order=ASC");
    ?>

    or

    <?php
    wp_reset_query();
    query_posts("cat=19&posts_per_page=5&orderby=date&order=DESC");
    ?>

    • 01/16/12 6:32am

      Arnav Joy says:

      try other field as


      <?php
      wp_reset_query();
      query_posts("cat=19&posts_per_page=5&orderby=title&order=ASC");
      ?>

  • avatar
    Last edited:
    01/16/12
    6:21am
    Fahd Murtaza says:

    Nothing wrong with the original code, sometimes, passing parameters like thjis helps. And its more useful for future edits :)



    <?php

    //query_posts("cat=19&posts_per_page=5&orderby=date");

    rewind_posts();

    $args = array(
    'cat' => 19,
    'posts_per_page'=>5,
    'orderby'='date',
    'order' => 'ASC'
    );
    query_posts( $args );

    ?>

  • avatar
    Last edited:
    01/16/12
    6:33am
    Sébastien | French WordpressDesigner says:

    hey, by default your posts are order by date :-)

    so <?php query_posts("cat=19&posts_per_page=5"); ?>
    and that's all

    Previous versions of this answer: 01/16/12 at 6:33am

  • avatar
    Last edited:
    01/16/12
    6:29am
    Matt Varone says:

    Hi Jennie,

    Try reseting your query and switching the order of query_posts around:


    wp_reset_query();
    query_posts( array ( 'cat' => 19, 'orderby' => 'date', 'posts_per_page' => '5' ) );


    Kind Regards!

This question has expired.



Sébastien | French WordpressDesigner, Jennie Routley, Luis Abarca voted on this question.



Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.