[Plugin: Co-Authors Plus] Found a bug; Solution included
-
I ran into an issue with your plugin when using it with my customized theme. My theme runs a wp_query to get all posts from a particular category and then based on some other criteria pulls out a random header image from one of those posts. Anyway, my code:
$my_query = new WP_Query('showposts=20&category_name=header');
was not generating any results when I viewed the author page (/author/username). Digging in, I found that it was running this query:SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) 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_relationships.term_taxonomy_id IN (28) ) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 20
I tracked the problem back to the posts_join_filter function in your plugin. I changed the function to check for each join separately instead of as a group and that solved the problem. Here’s the new code if you want it:
function posts_join_filter( $join ){ global $wpdb, $wp_query; if( is_author() ){ // Check to see that JOIN hasn't already been added. Props michaelingp $join_string1 = " INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)"; $join_string2 = " INNER JOIN {$wpdb->term_taxonomy} ON ( {$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id )"; if( strpos( $join, trim($join_string1) ) === false ) { $join .= $join_string1; } if( strpos( $join, trim($join_string2) ) === false ) { $join .= $join_string2; } } return $join; }
If you could add this to the plugin I’d be really happy. Hope it helps.
Thanks,
Nate
- The topic ‘[Plugin: Co-Authors Plus] Found a bug; Solution included’ is closed to new replies.