• I created an archive for each author using author.php and co-authors plus causes an issue. When I visit an authors archive – /author/username, for any user other than the first created user I see an sql error on the page:
    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 = '12'07 OR (wp_term_taxonomy.taxonomy = 'author' AND wp_term_taxonomy.term_id = '51'))) 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 = '51' OR wp_term_taxonomy.term_id = '12',2,1 ),0 ) ) <> 1 ORDER BY wp_posts.post_date DESC LIMIT 0, 9.

    Even when I hide errors from the page, the rest of the page – the WordPress loop that is run on that page returns no posts.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter dhruveonmars

    (@dhruveonmars)

    I encountered the same error, this is the bug in co-authors plugin.
    There is a quick fix for it:
    Search for function posts_where_filter() in co-author-plus.php and then search for line

    $where = preg_replace( '/(\b(?:' . $wpdb->posts . '\.)?post_author\s*=\s*(' . get_current_user_id() . '))/', $current_user_query, $where, -1 ); #' . $wpdb->postmeta . '.meta_id IS NOT NULL AND
    near the end of this function

    You should replace it with

    $where = preg_replace( '/(\b(?:' . $wpdb->posts . '\.)?post_author\s*=\s*(' . get_current_user_id() . ')\b)/', $current_user_query, $where, -1 ); #' . $wpdb->postmeta . '.meta_id IS NOT NULL AND

    I added \b to only match on word boundaries. Previously it matched current user id as a substring of post_author id and that caused problems.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Co-authors Plus Author Archive SQL Issue’ is closed to new replies.