I’ve got a page that has a category list at the top, and should normally list posts below it. The category list is created using:
<?php $display_categories = array( 4, 7, 8, 9, 21, 1); $i = 1;
foreach ( $display_categories as $category ) { ?>
<div>
<?php single_cat_title(); ?> //etc
</div>
<?php }
?>
However, this seems to make the post loop order posts by category. I want it to ignore category ordering and order by date in descending order. I’ve created a new WP_Query since according to the docs you can’t use query_posts() twice, so just in case.
<?php $q = new WP_Query( "cat=-1&showposts=15&orderby=date&order=DESC" );
if ( $q->have_posts() ) :
while ( $q->have_posts() ) : $q->the_post(); ?>
the_title(); // etc
endwhile;
endif;
?>
However, this still seems to be ordered by category (the same order as the list above) and then by date, as opposed to just by date.
I’ve had problems with this before as well.
Try this:
The important line is
global $post;
.That should reset your global query. The
setup_postdata($post)
method is necessary to give you access to functions likethe_author()
orthe_content()
.-Chris
I don’t have any experience with wordpress, but a couple of possibilities:
query_posts()
with, I don’t know if that causes a problem or not.Parameters and their effects are described here: http://codex.wordpress.org/Template_Tags/query_posts#Parameters
query_posts is finicky sometimes. Try something like this and see if it works:
Since that’s not the issue, try adding update_post_caches($posts) to the second loop, like this:
Supposedly this solves some plugin problems.