WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/29/2014 09:40:04 PM (7 years ago)
Author:
kovshenin
Message:

Use a nested meta query when querying by role in WP_User_Query.

If a user query includes a meta query together with a role argument,
nest the original meta query and append the role meta query with an
AND relationship.

fixes #23849, #27026.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/user.php

    r30033 r30094  
    716716        }
    717717
     718        $meta_query = new WP_Meta_Query();
     719        $meta_query->parse_query_vars( $qv );
     720
    718721        $role = '';
    719722        if ( isset( $qv['role'] ) )
     
    729732            }
    730733
    731             if ( empty( $qv['meta_query'] ) || ! in_array( $cap_meta_query, $qv['meta_query'], true ) ) {
    732                 $qv['meta_query'][] = $cap_meta_query;
     734            if ( empty( $meta_query->queries ) ) {
     735                $meta_query->queries = array( $cap_meta_query );
     736            } elseif ( ! in_array( $cap_meta_query, $meta_query->queries, true ) ) {
     737                // Append the cap query to the original queries and reparse the query.
     738                $meta_query->queries = array(
     739                    'relation' => 'AND',
     740                    array( $meta_query->queries, $cap_meta_query ),
     741                );
    733742            }
    734         }
    735 
    736         $meta_query = new WP_Meta_Query();
    737         $meta_query->parse_query_vars( $qv );
     743
     744            $meta_query->parse_query_vars( $meta_query->queries );
     745        }
    738746
    739747        if ( !empty( $meta_query->queries ) ) {
Note: See TracChangeset for help on using the changeset viewer.