Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

query_posts orderby not working WordPress

  • SOLVED

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">

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

<?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

Answers (8)

2012-01-16

Julio Potier answers:

hello

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

See you soon !


Jennie Routley comments:

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!

2012-01-16

Francisco Javier Carazo Gil answers:

Hi,

Try also to set the order type ASC or DESC:

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



Francisco Javier Carazo Gil comments:

In your case:

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


And remember is "post_date" no "date".

2012-01-16

Milan Petrovic answers:

To order by date, you are using function wrong. It should be:

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

2012-01-16

Jens Filipsson answers:

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

2012-01-16

Arnav Joy answers:

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


Arnav Joy comments:

try other field as


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

2012-01-16

Fahad Murtaza answers:

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

?>

2012-01-16

Sébastien | French WordpressDesigner answers:

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

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


Sébastien | French WordpressDesigner comments:

just use order = ASC or DESC to order the post

2012-01-16

Matt Varone answers:

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!