: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$search_orderby = apply_filters( 'posts_search_orderby', $search_orderby, $this );
$orderby = $orderby ? $search_orderby . ', ' . $orderby : $search_orderby;
if ( is_array( $post_type ) && count( $post_type ) > 1 ) {
$post_type_cap = 'multiple_post_type';
if ( is_array( $post_type ) ) {
$post_type = reset( $post_type );
$post_type_object = get_post_type_object( $post_type );
if ( empty( $post_type_object ) ) {
$post_type_cap = $post_type;
if ( isset( $q['post_password'] ) ) {
$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_password = %s", $q['post_password'] );
if ( empty( $q['perm'] ) ) {
} elseif ( isset( $q['has_password'] ) ) {
$where .= sprintf( " AND {$wpdb->posts}.post_password %s ''", $q['has_password'] ? '!=' : '=' );
if ( ! empty( $q['comment_status'] ) ) {
$where .= $wpdb->prepare( " AND {$wpdb->posts}.comment_status = %s ", $q['comment_status'] );
if ( ! empty( $q['ping_status'] ) ) {
$where .= $wpdb->prepare( " AND {$wpdb->posts}.ping_status = %s ", $q['ping_status'] );
$skip_post_status = false;
if ( 'any' === $post_type ) {
$in_search_post_types = get_post_types( array( 'exclude_from_search' => false ) );
if ( empty( $in_search_post_types ) ) {
$post_type_where = ' AND 1=0 ';
$skip_post_status = true;
$post_type_where = " AND {$wpdb->posts}.post_type IN ('" . implode( "', '", array_map( 'esc_sql', $in_search_post_types ) ) . "')";
} elseif ( ! empty( $post_type ) && is_array( $post_type ) ) {
// Sort post types to ensure same cache key generation.
$post_type_where = " AND {$wpdb->posts}.post_type IN ('" . implode( "', '", esc_sql( $post_type ) ) . "')";
} elseif ( ! empty( $post_type ) ) {
$post_type_where = $wpdb->prepare( " AND {$wpdb->posts}.post_type = %s", $post_type );
$post_type_object = get_post_type_object( $post_type );
} elseif ( $this->is_attachment ) {
$post_type_where = " AND {$wpdb->posts}.post_type = 'attachment'";
$post_type_object = get_post_type_object( 'attachment' );
} elseif ( $this->is_page ) {
$post_type_where = " AND {$wpdb->posts}.post_type = 'page'";
$post_type_object = get_post_type_object( 'page' );
$post_type_where = " AND {$wpdb->posts}.post_type = 'post'";
$post_type_object = get_post_type_object( 'post' );
if ( ! empty( $post_type_object ) ) {
$edit_others_cap = $post_type_object->cap->edit_others_posts;
$read_private_cap = $post_type_object->cap->read_private_posts;
$edit_others_cap = 'edit_others_' . $post_type_cap . 's';
$read_private_cap = 'read_private_' . $post_type_cap . 's';
$user_id = get_current_user_id();
if ( $skip_post_status ) {
$where .= $post_type_where;
} elseif ( ! empty( $q['post_status'] ) ) {
$where .= $post_type_where;
$q_status = $q['post_status'];
if ( ! is_array( $q_status ) ) {
$q_status = explode( ',', $q_status );
if ( in_array( 'any', $q_status, true ) ) {
foreach ( get_post_stati( array( 'exclude_from_search' => true ) ) as $status ) {
if ( ! in_array( $status, $q_status, true ) ) {
$e_status[] = "{$wpdb->posts}.post_status <> '$status'";
foreach ( get_post_stati() as $status ) {
if ( in_array( $status, $q_status, true ) ) {
if ( 'private' === $status ) {
$p_status[] = "{$wpdb->posts}.post_status = '$status'";
$r_status[] = "{$wpdb->posts}.post_status = '$status'";
if ( empty( $q['perm'] ) || 'readable' !== $q['perm'] ) {
$r_status = array_merge( $r_status, $p_status );
if ( ! empty( $e_status ) ) {
$statuswheres[] = '(' . implode( ' AND ', $e_status ) . ')';
if ( ! empty( $r_status ) ) {
if ( ! empty( $q['perm'] ) && 'editable' === $q['perm'] && ! current_user_can( $edit_others_cap ) ) {
$statuswheres[] = "({$wpdb->posts}.post_author = $user_id " . 'AND (' . implode( ' OR ', $r_status ) . '))';
$statuswheres[] = '(' . implode( ' OR ', $r_status ) . ')';
if ( ! empty( $p_status ) ) {
if ( ! empty( $q['perm'] ) && 'readable' === $q['perm'] && ! current_user_can( $read_private_cap ) ) {
$statuswheres[] = "({$wpdb->posts}.post_author = $user_id " . 'AND (' . implode( ' OR ', $p_status ) . '))';
$statuswheres[] = '(' . implode( ' OR ', $p_status ) . ')';
if ( $post_status_join ) {
$join .= " LEFT JOIN {$wpdb->posts} AS p2 ON ({$wpdb->posts}.post_parent = p2.ID) ";
foreach ( $statuswheres as $index => $statuswhere ) {
$statuswheres[ $index ] = "($statuswhere OR ({$wpdb->posts}.post_status = 'inherit' AND " . str_replace( $wpdb->posts, 'p2', $statuswhere ) . '))';
$where_status = implode( ' OR ', $statuswheres );
if ( ! empty( $where_status ) ) {
$where .= " AND ($where_status)";
} elseif ( ! $this->is_singular ) {
if ( 'any' === $post_type ) {
$queried_post_types = get_post_types( array( 'exclude_from_search' => false ) );
} elseif ( is_array( $post_type ) ) {
$queried_post_types = $post_type;
} elseif ( ! empty( $post_type ) ) {
$queried_post_types = array( $post_type );
$queried_post_types = array( 'post' );
if ( ! empty( $queried_post_types ) ) {
sort( $queried_post_types );
$status_type_clauses = array();
foreach ( $queried_post_types as $queried_post_type ) {
$queried_post_type_object = get_post_type_object( $queried_post_type );
$type_where = '(' . $wpdb->prepare( "{$wpdb->posts}.post_type = %s AND (", $queried_post_type );
$public_statuses = get_post_stati( array( 'public' => true ) );
$status_clauses = array();
foreach ( $public_statuses as $public_status ) {
$status_clauses[] = "{$wpdb->posts}.post_status = '$public_status'";
$type_where .= implode( ' OR ', $status_clauses );
// Add protected states that should show in the admin all list.
$admin_all_statuses = get_post_stati(
'show_in_admin_all_list' => true,
foreach ( $admin_all_statuses as $admin_all_status ) {
$type_where .= " OR {$wpdb->posts}.post_status = '$admin_all_status'";
// Add private states that are visible to current user.
if ( is_user_logged_in() && $queried_post_type_object instanceof WP_Post_Type ) {
$read_private_cap = $queried_post_type_object->cap->read_private_posts;
$private_statuses = get_post_stati( array( 'private' => true ) );
foreach ( $private_statuses as $private_status ) {
$type_where .= current_user_can( $read_private_cap ) ? " \nOR {$wpdb->posts}.post_status = '$private_status'" : " \nOR ({$wpdb->posts}.post_author = $user_id AND {$wpdb->posts}.post_status = '$private_status')";
$status_type_clauses[] = $type_where;
if ( ! empty( $status_type_clauses ) ) {
$where .= ' AND (' . implode( ' OR ', $status_type_clauses ) . ')';
$where .= $post_type_where;
* Apply filters on where and join prior to paging so that any
* manipulations to them are reflected in the paging by day queries.
if ( ! $q['suppress_filters'] ) {
* Filters the WHERE clause of the query.
* @param string $where The WHERE clause of the query.
* @param WP_Query $query The WP_Query instance (passed by reference).
$where = apply_filters_ref_array( 'posts_where', array( $where, &$this ) );
* Filters the JOIN clause of the query.
* @param string $join The JOIN clause of the query.
* @param WP_Query $query The WP_Query instance (passed by reference).
$join = apply_filters_ref_array( 'posts_join', array( $join, &$this ) );
if ( empty( $q['nopaging'] ) && ! $this->is_singular ) {
$page = absint( $q['paged'] );
// If 'offset' is provided, it takes precedence over 'paged'.
if ( isset( $q['offset'] ) && is_numeric( $q['offset'] ) ) {
$q['offset'] = absint( $q['offset'] );
$pgstrt = $q['offset'] . ', ';
$pgstrt = absint( ( $page - 1 ) * $q['posts_per_page'] ) . ', ';
$limits = 'LIMIT ' . $pgstrt . $q['posts_per_page'];
if ( $this->is_comment_feed && ! $this->is_singular ) {
if ( $this->is_archive || $this->is_search ) {
$cjoin = "JOIN {$wpdb->posts} ON ( {$wpdb->comments}.comment_post_ID = {$wpdb->posts}.ID ) $join ";
$cwhere = "WHERE comment_approved = '1' $where";
$cgroupby = "{$wpdb->comments}.comment_id";
} else { // Other non-singular, e.g. front.
$cjoin = "JOIN {$wpdb->posts} ON ( {$wpdb->comments}.comment_post_ID = {$wpdb->posts}.ID )";
$cwhere = "WHERE ( post_status = 'publish' OR ( post_status = 'inherit' AND post_type = 'attachment' ) ) AND comment_approved = '1'";
if ( ! $q['suppress_filters'] ) {
* Filters the JOIN clause of the comments feed query before sending.
* @param string $cjoin The JOIN clause of the query.
* @param WP_Query $query The WP_Query instance (passed by reference).
$cjoin = apply_filters_ref_array( 'comment_feed_join', array( $cjoin, &$this ) );
* Filters the WHERE clause of the comments feed query before sending.
* @param string $cwhere The WHERE clause of the query.
* @param WP_Query $query The WP_Query instance (passed by reference).
$cwhere = apply_filters_ref_array( 'comment_feed_where', array( $cwhere, &$this ) );
* Filters the GROUP BY clause of the comments feed query before sending.
* @param string $cgroupby The GROUP BY clause of the query.
* @param WP_Query $query The WP_Query instance (passed by reference).
$cgroupby = apply_filters_ref_array( 'comment_feed_groupby', array( $cgroupby, &$this ) );
* Filters the ORDER BY clause of the comments feed query before sending.
* @param string $corderby The ORDER BY clause of the query.
* @param WP_Query $query The WP_Query instance (passed by reference).
$corderby = apply_filters_ref_array( 'comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) );
* Filters the LIMIT clause of the comments feed query before sending.
* @param string $climits The JOIN clause of the query.
* @param WP_Query $query The WP_Query instance (passed by reference).
$climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option( 'posts_per_rss' ), &$this ) );
$cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : '';
$corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : '';
$climits = ( ! empty( $climits ) ) ? $climits : '';
$comments_request = "SELECT $distinct {$wpdb->comments}.comment_ID FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits";
$key = md5( $comments_request );
$last_changed = wp_cache_get_last_changed( 'comment' ) . ':' . wp_cache_get_last_changed( 'posts' );
$cache_key = "comment_feed:$key:$last_changed";
$comment_ids = wp_cache_get( $cache_key, 'comment-queries' );
if ( false === $comment_ids ) {
$comment_ids = $wpdb->get_col( $comments_request );
wp_cache_add( $cache_key, $comment_ids, 'comment-queries' );
_prime_comment_caches( $comment_ids );
// Convert to WP_Comment.
$this->comments = array_map( 'get_comment', $comment_ids );
$this->comment_count = count( $this->comments );
foreach ( $this->comments as $comment ) {
$post_ids[] = (int) $comment->comment_post_ID;
$post_ids = implode( ',', $post_ids );
$where = "AND {$wpdb->posts}.ID IN ($post_ids) ";
$pieces = array( 'where', 'groupby', 'join', 'orderby', 'distinct', 'fields', 'limits' );
* Apply post-paging filters on where and join. Only plugins that
* manipulate paging queries should use these hooks.
if ( ! $q['suppress_filters'] ) {
* Filters the WHERE clause of the query.
* Specifically for manipulating paging queries.
* @param string $where The WHERE clause of the query.
* @param WP_Query $query The WP_Query instance (passed by reference).
$where = apply_filters_ref_array( 'posts_where_paged', array( $where, &$this ) );
* Filters the GROUP BY clause of the query.
* @param string $groupby The GROUP BY clause of the query.
* @param WP_Query $query The WP_Query instance (passed by reference).
$groupby = apply_filters_ref_array( 'posts_groupby', array( $groupby, &$this ) );
* Filters the JOIN clause of the query.
* Specifically for manipulating paging queries.
* @param string $join The JOIN clause of the query.
* @param WP_Query $query The WP_Query instance (passed by reference).
$join = apply_filters_ref_array( 'posts_join_paged', array( $join, &$this ) );
* Filters the ORDER BY clause of the query.
* @param string $orderby The ORDER BY clause of the query.
* @param WP_Query $query The WP_Query instance (passed by reference).
$orderby = apply_filters_ref_array( 'posts_orderby', array( $orderby, &$this ) );
* Filters the DISTINCT clause of the query.
* @param string $distinct The DISTINCT clause of the query.
* @param WP_Query $query The WP_Query instance (passed by reference).
$distinct = apply_filters_ref_array( 'posts_distinct', array( $distinct, &$this ) );
* Filters the LIMIT clause of the query.
* @param string $limits The LIMIT clause of the query.
* @param WP_Query $query The WP_Query instance (passed by reference).
$limits = apply_filters_ref_array( 'post_limits', array( $limits, &$this ) );
* Filters the SELECT clause of the query.
* @param string $fields The SELECT clause of the query.
* @param WP_Query $query The WP_Query instance (passed by reference).
$fields = apply_filters_ref_array( 'posts_fields', array( $fields, &$this ) );
* Filters all query clauses at once, for convenience.
* Covers the WHERE, GROUP BY, JOIN, ORDER BY, DISTINCT,
* fields (SELECT), and LIMIT clauses.
* @param string[] $clauses {
* Associative array of the clauses for the query.
* @type string $where The WHERE clause of the query.
* @type string $groupby The GROUP BY clause of the query.
* @type string $join The JOIN clause of the query.
* @type string $orderby The ORDER BY clause of the query.
* @type string $distinct The DISTINCT clause of the query.
* @type string $fields The SELECT clause of the query.
* @type string $limits The LIMIT clause of the query.
* @param WP_Query $query The WP_Query instance (passed by reference).
$clauses = (array) apply_filters_ref_array( 'posts_clauses', array( compact( $pieces ), &$this ) );
$where = isset( $clauses['where'] ) ? $clauses['where'] : '';
$groupby = isset( $clauses['groupby'] ) ? $clauses['groupby'] : '';
$join = isset( $clauses['join'] ) ? $clauses['join'] : '';
$orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
$distinct = isset( $clauses['distinct'] ) ? $clauses['distinct'] : '';
$fields = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
$limits = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
* Fires to announce the query's current selection parameters.
* For use by caching plugins.
* @param string $selection The assembled selection query.
do_action( 'posts_selection', $where . $groupby . $orderby . $limits . $join );
* Filters again for the benefit of caching plugins.
* Regular plugins should use the hooks above.
if ( ! $q['suppress_filters'] ) {
* Filters the WHERE clause of the query.
* For use by caching plugins.
* @param string $where The WHERE clause of the query.
* @param WP_Query $query The WP_Query instance (passed by reference).
$where = apply_filters_ref_array( 'posts_where_request', array( $where, &$this ) );
* Filters the GROUP BY clause of the query.
* For use by caching plugins.