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
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); ?>&w=170&h=120&zc=1&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); ?>&w=170&h=120&zc=1&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.
-

Last edited:
01/16/12
6:16amJulio 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!
- 01/16/12 6:49am
-

Last edited:
01/16/12
6:18amFrancisco 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".
- 01/16/12 6:20am
-

Last edited:
01/16/12
6:19am -

Last edited:
01/16/12
6:19amJens 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"); ?>
-

Last edited:
01/16/12
6:20amArnav 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");
?>
- 01/16/12 6:32am
-

Last edited:
01/16/12
6:21amFahd 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 );
?> -

Last edited:
01/16/12
6:33amSé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
- 01/16/12 6:27am
Sébastien | French WordpressDesigner says:just use order = ASC or DESC to order the post
- 01/16/12 6:27am
-

Last edited:
01/16/12
6:29amMatt 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.
