Support » Plugin: Co-Authors Plus » [Plugin: Co-Authors Plus] Bug in posts_join_filter() ?

  • michaelingp


    posts_join_filter() adds some SQL to the query string. However, if you are using query_posts() to modify the default search for a page, posts_join_filter() has already run (courtesy of WordPress before entering the theme page), and the second running (in response to the call to query_posts()) adds the SQL again, which results in an SQL syntax error, and no posts returned. I think it should probably check to see if it’s already run. I used strpos() to check if $join already contains the new SQL, and if so, skip adding it. So far, this has worked for me, with no bad effects I’ve noticed.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Mohammad Jangda


    Would you mind sending me the code? I’ll gladly add it to the plugin.

    Thanks for the report @michaelingp



    function posts_join_filter($join){
    global $wpdb,$wp_query;

    $join_string = ” INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)”;
    if (strpos($join,$join_string) === FALSE) {
    $join .= $join_string;
    return $join;

    Basically, I just created a variable equal to the same text you appended, then checked to see if was already there before appending it.

    By the way, I also ran into a conflict between co-authors-plus and collapsing-archives, but that problem looks like its not in your code or implementation. I think your implementation is fine, I just mention this in case someone else brings it up.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Co-Authors Plus] Bug in posts_join_filter() ?’ is closed to new replies.