WordPress.org

Ready to get started?Download WordPress

Forums

Co-Authors Plus
Bug in posts_join_filter() ? (3 posts)

  1. michaelingp
    Member
    Posted 3 years ago #

    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.

  2. Mohammad Jangda
    Member
    Plugin Author

    Posted 3 years ago #

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

    Thanks for the report @michaelingp

  3. michaelingp
    Member
    Posted 3 years ago #

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

    if(is_author()){
    $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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic