[wp-hackers] 2.1: Alternative to query_posts?
peter.westwood at ftwr.co.uk
Wed Jan 10 21:42:37 GMT 2007
> On 1/10/07, Ryan Boren <ryan at boren.nu> wrote:
>> On 1/10/07, Joefish <joefish.hackers at feastofcrumbs.com> wrote:
>> > This was working great for me with 2.0.x, but with 2.1 beta 1 and beta
>> > 2, it only works when category 48 is not empty, i.e., when I have a
>> > sticky post. In 2.0.x, if the category is empty, the if (have_posts())
>> > bit would return false and the first loop would have no output. But
>> > with 2.1, the query returns an SQL error and dies.
>> > Is this a bug in 2.1, or should I be setting up the loop in some other
>> > way?
>> Sounds like a bug. What is the SQL error you got?
> Thanks for your response, Ryan. Here's the message:
> WordPress database error: [You have an error in your SQL syntax; check
> the manual that corresponds to your MySQL server version for the right
> syntax to use near '48 AND (post_type = 'post' AND (post_status =
> 'publish' OR post_status = 'privat' at line 1]
> SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts LEFT JOIN
> wp_post2cat ON (wp_posts.ID = wp_post2cat.post_id) WHERE 1=1 48 AND
> (post_type = 'post' AND (post_status = 'publish' OR post_status =
> 'private')) GROUP BY wp_posts.ID ORDER BY post_date DESC LIMIT 0, 10
> That's a copy and paste, so the post_status = 'privat' near the
> beginning is not my typo... just noticed that.
Looking through the code I can't see an obvious bug in query.php that
would cause this.
You should have something like the following in the generated query
rather than what you do have:
SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts LEFT JOIN
wp_post2cat ON (wp_posts.ID = wp_post2cat.post_id) WHERE 1=1
AND category_id IN (48) AND (post_type = 'post' AND (post_status =
'publish' OR post_status = 'private')) GROUP BY wp_posts.ID ORDER BY
post_date DESC LIMIT 0, 10
Do you have any plugins installed that filter the WHERE clause?
More information about the wp-hackers