Multiple plugins messing up SQL query
-
I’ve been trying to figure out how to get both private categories and front page categories to play nice… And what I am seeing has me baffled.
As far as I can figure out the code, each plugin concatenates its own stuff to the SQL query. So far so good – except that each plugin appears to use the same bit of code – like this:
$query . ‘ LEFT JOIN ‘ . $table_prefix .
‘post2cat ON (‘ . $table_prefix . ‘posts.ID = ‘ .
$table_prefix . ‘post2cat.post_id) ‘If you have two plugins, you get a double LEFT JOIN query like this:
SELECT COUNT(ID) FROM wp_posts /*index*/ LEFT JOIN wp_post2cat ON wp_posts.ID = wp_post2cat.post_id LEFT JOIN wp_post2cat ON (wp_posts.ID = wp_post2cat.post_id) WHERE 1=1 AND post_date_gmt <= ‘2005-08-16 13:27:59’ AND (post_status = “publish” OR post_author = 1 AND post_status != ‘draft’ AND post_status != ‘static’) AND category_id <> 4 AND category_id <> 5
which pukes…. SQL must reformat that query before spewing forth the error, since the concat statement actually results in something like this:
SELECT COUNT(ID) FROM wp_posts /*index*/ LEFT JOIN wp_post2cat ON wp_posts.ID = wp_post2cat.post_id WHERE 1=1 AND post_date_gmt <= ‘2005-08-16 13:27:59’ AND (post_status = “publish” OR post_author = 1 AND post_status != ‘draft’ AND post_status != ‘static’) LEFT JOIN wp_post2cat ON (wp_posts.ID = wp_post2cat.post_id) WHERE category_id <> 4 AND category_id <> 5
It seems to me that instead of a simple ‘.=’ there should be a wp_join($new_query) that would check the content of the join statement and correctly add the new search requirements, no?
If someone is willing to check my SQL syntax, I will make a stab at writing that function….
- The topic ‘Multiple plugins messing up SQL query’ is closed to new replies.