wp query – WordPress WP_User_Query ignores the `meta_query` when called from an Ajax function

Question

I have an ajax function that runs the following WP_User_Query:

        $args2 = array(
            'meta_query' => array(
                    'gender' => array(
                        'key'     => 'gender',
                        'value'   => 'female',
                         'compare' => '='
                    )
                    ),
                    'number' => 10
         );
        $user_query = new WP_User_Query( $args2 );

The query is returning unfiltered results, basically ignoring the meta_query. It works fine if I run it from functions.php or from a template file, but not from ajax. Any idea why?

This is the request string when it works:

                SELECT SQL_CALC_FOUND_ROWS wp_users.ID
                FROM wp_users INNER JOIN wp_usermeta ON ( wp_users.ID = wp_usermeta.user_id 
                )
                WHERE 1=1 AND ( 
                ( wp_usermeta.meta_key = 'gender' AND wp_usermeta.meta_value="female" )
                )
                ORDER BY user_login ASC
                LIMIT 0, 10

And this is the one from the ajax function:

                SELECT SQL_CALC_FOUND_ROWS wp_users.ID
                FROM wp_users
                WHERE 1=1
                ORDER BY user_login ASC
                LIMIT 0, 10

0
Carlos G 4 weeks 2022-12-29T18:41:30-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse