Skip to content

Commit

Permalink
[#388] Modify where condition when WordPress generates `post_author I…
Browse files Browse the repository at this point in the history
…N (id)` in query
  • Loading branch information
sanketio committed Jan 30, 2018
1 parent bfd7436 commit fd08f52
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions co-authors-plus.php
Expand Up @@ -703,9 +703,18 @@ function posts_where_filter( $where, $query ) {
}
$terms_implode = rtrim( $terms_implode, ' OR' );

$id = is_author() ? get_queried_object_id() : '\d';
$id = is_author() ? get_queried_object_id() : '\d+';

$where = preg_replace( '/(\b(?:' . $wpdb->posts . '\.)?post_author\s*=\s*(' . $id . '))/', '(' . $maybe_both_query . ' ' . $terms_implode . ')', $where, -1 ); #' . $wpdb->postmeta . '.meta_id IS NOT NULL AND
// When WordPress generates query as 'post_author IN (id)'.
if ( false !== strpos( $where, "{$wpdb->posts}.post_author IN " ) ) {

$maybe_both_query = $maybe_both ? '$0 OR' : '';

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

} else {
$where = preg_replace( '/(\b(?:' . $wpdb->posts . '\.)?post_author\s*=\s*(' . $id . '))/', '(' . $maybe_both_query . ' ' . $terms_implode . ')', $where, -1 ); #' . $wpdb->postmeta . '.meta_id IS NOT NULL AND
}

// the block targets the private posts clause (if it exists)
if (
Expand Down

0 comments on commit fd08f52

Please sign in to comment.