WP_query simply doesn't work with orderby => ID
Usually I find the answer on an existing question. But this one has me stumped.
This custom query is in my sidebar and works fine on every other page (including singles and custom post type archives) EXCEPT the index page and all the regular post type archives. Only there, the
'orderby' => 'ID'array parameter, or any other parameter such as
'order' => 'ASC',simply refuses to work. It will only display data by default date and descending order. Here’s the code for one of these custom queries:
<?php $the_query = new WP_Query(array( 'post_type' => 'library', 'orderby' => 'ID', 'posts_per_page' => '1', )); while ($the_query->have_posts()) : $the_query->the_post(); ?> <div style="display: inline; padding: 3px 0 0 2px;"> <a href="<?php the_permalink() ?>"><?php the_post_thumbnail('library-thumbnail'); ?></a> </div> <?php endwhile; wp_reset_query(); ?>
By echoing the query request, I get this (only on index.php and all the regular post type archives):
SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'library' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') ORDER BY wp_posts.post_date DESC LIMIT 0, 1
So no plugins seem to be interfering. But it still only wants to “ORDER BY wp_posts.post_date DESC” and not “… wp_posts.ID”.
Again, this query works fine and orders perfectly on all other pages except the index and blog archive pages. No plugins are interfering (as the query request echo indicates) and I reset the query every time.
Much gratitude in response for any support.
- The topic ‘WP_query simply doesn't work with orderby => ID’ is closed to new replies.