This worked for me though I’m excluding category 1 and displaying all posts per page:
<?php
$args=array(
'category__not_in' => 1,
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby'=> 'id',
'order' => 'desc',
'ignore_sticky_posts' => 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
echo 'post id: ',$post->ID;
endwhile;
}
?>
Thread Starter
ahmadj
(@ahmadj)
I copied your code verbatim but it doesn’t seem to work… I tested by creating new posts and setting the dates far in the past. These posts have higher IDs than the others, but still appear further down the list, in date order.
Any idea what could be the issue?
Are you sure you are putting the code in the proper place? Do you see the ‘post id: 123’ or whatever displayed?
Thread Starter
ahmadj
(@ahmadj)
Yup, I see the post IDs displayed. That’s how I can tell the ordering is not working. Have you tested it with out-of-order-ID-compared-to-date posts?
This is strange… Could it be a bug in WP 3.1.1?
Nope it’s my fault. That should read:
'orderby'=> 'ID',
Note the capitalization of ID
<?php
$args=array(
'category__not_in' => 1,
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby'=> 'ID',
'order' => 'desc',
'ignore_sticky_posts' => 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
echo 'post id: ',$post->ID;
endwhile;
}
?>
Thread Starter
ahmadj
(@ahmadj)
Magnifique! It works! Thanks 🙂