Odd SQL query & subsequent error when querying some co-authors
-
Hi- I’m getting a SQL error based on a malformed query when trying to view co-author archives (front-end and in the admin).
Here’s an example of the malformed query that WP is firing to get the posts for the co-author:
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships AS tr1 ON (wp_posts.ID = tr1.object_id) LEFT JOIN wp_term_taxonomy ON ( tr1.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id ) WHERE 1=1 AND ((wp_term_taxonomy.taxonomy = 'author' AND wp_term_taxonomy.term_id = '24'148 OR (wp_term_taxonomy.taxonomy = 'author' AND wp_term_taxonomy.term_id = '2149'))) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'acf-disabled' OR wp_posts.post_status = 'future' OR wp_posts.post_status = 'draft' OR wp_posts.post_status = 'pending' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID HAVING MAX( IF ( wp_term_taxonomy.taxonomy = 'author', IF ( wp_term_taxonomy.term_id = '2149' OR wp_term_taxonomy.term_id = '24',2,1 ),0 ) ) <> 1 ORDER BY wp_posts.post_date DESC LIMIT 0, 20
Notice in the where clause:
WHERE 1=1 AND ((wp_term_taxonomy.taxonomy = 'author' AND wp_term_taxonomy.term_id = '24'148 OR
that ’24’148 bit… The user in question has an ID of 1148. In all of the instances where this chokes, the error is in the same spot where the ID is being truncated and mashed into the query like that.
There are other users where the query comes out just fine:
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships AS tr1 ON (wp_posts.ID = tr1.object_id) LEFT JOIN wp_term_taxonomy ON ( tr1.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id ) WHERE 1=1 AND ((wp_posts.post_author = 940 OR (wp_term_taxonomy.taxonomy = 'author' AND wp_term_taxonomy.term_id = '2154'))) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'acf-disabled' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID HAVING MAX( IF ( wp_term_taxonomy.taxonomy = 'author', IF ( wp_term_taxonomy.term_id = '2154' OR wp_term_taxonomy.term_id = '24',2,1 ),0 ) ) <> 1 ORDER BY wp_posts.post_date DESC LIMIT 0, 10
It doesn’t seem to matter if the author is a co-author or not, as I’m seeing both good & bad queries on authors who aren’t co-authors anywhere in the DB. Likewise, I’m seeing good & bad queries on some co-authors (but not all), in both the first slot (as the author) as well as secondary slots (as tax terms).
- The topic ‘Odd SQL query & subsequent error when querying some co-authors’ is closed to new replies.