[wp-hackers] query_posts orderby not working properly

Mike Schinkel mikeschinkel at newclarity.net
Sat Aug 14 07:27:12 UTC 2010


Brian,

You've got a plugin or a theme hook that's causing the problem (either that or you've got sticky posts that are confusing you.)

I ran this query with v3.0.1:

	query_posts('cat=1&posts_per_page=-1&orderby=title&order=ASC');

And on line 2416 of /wp-includes/query.php $this->request contained the following SQL (I pretty formatted it to make it easier to read):

SELECT
	wp_posts.*
FROM
	wp_posts
	INNER JOIN wp_term_relationships ON wp_posts.ID = wp_term_relationships.object_id
	INNER JOIN wp_term_taxonomy ON wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id
WHERE
	1 = 1
	AND wp_term_taxonomy.taxonomy = 'category'
	AND wp_term_taxonomy.term_id IN('1')
	AND wp_posts.post_type = 'post'
	AND wp_posts.post_status = 'publish'
GROUP BY
	wp_posts.ID
ORDER BY
	wp_posts.post_title ASC

If sticky posts are the problem this should solve it:

	query_posts('cat=1&posts_per_page=-1&orderby=title&order=ASC&caller_get_posts=1');

Otherwise try disabling all plugins and switch to a default theme to see if it fixes it.  If so, start enabling things until you figure out which is causing the problem.

Hope this helps.

-Mike

On Aug 14, 2010, at 2:58 AM, Brian Fidler wrote:

> it gives me DESC order regardless of whether I choose ASC or DESC. I
> actually need ASC order.
> 
> 
> 
> On Fri, Aug 13, 2010 at 9:22 PM, Jake Goldman <
> wphackers at jakemgold.myfastmail.com> wrote:
> 
>> Valid options  for orderby and order:
>> 
>> 
>> http://codex.wordpress.org/Function_Reference/query_posts#Orderby_Parameters
>> 
>> Your first example certainly shouldn't work.  You can't order by a specific
>> post's title. I'm not sure why the second example isn't working for you, but
>> I can attest to the fact that it /does/ work.
>> 
>> What order does it give you?
>> 
>> Jake
>> 
>> 
>> On 8/13/2010 11:57 PM, Brian Fidler wrote:
>> 
>>> I'm having a problem getting a query to order properly. This is what I
>>> currently have:
>>> query_posts('cat='.$category->cat_ID.'&posts_per_page=-1&orderby='.
>>> $post->post_title . '&order=DESC');
>>> 
>>> I've also tried:
>>> 
>>> query_posts('cat='.$category->cat_ID.'&posts_per_page=-1&orderby=title&order=DESC');
>>> 
>>> Any idea what I could be missing?
>>> 
>>> thanks
>>> brian
>>> _______________________________________________
>>> wp-hackers mailing list
>>> wp-hackers at lists.automattic.com
>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>> 
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>> 
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list