• Resolved DamirCalusic

    (@webkreativ)


    Hi!

    I am trying to list users from the database based on a search and I am using the get_user() function. The goal is to list all users based on different meta_values and meta_keys inputed in the search field.

    Now, in the get_user function I use meta_query array to specify the attributes etc. based on the search. The problem here is that the get_user() lists all the users and I can echo out all meta_keys and meta_values etc. for the specific user BUT the meta_query does not work!

    The code is shown below.

    $till = base64_decode($_POST["till"]);
    $fall = base64_decode($_POST["fall"]);
    
    $args = array(
            'role' => 'nanny',
            'orderby' => 'first_name',
    	'meta_query' => array(
                    'relation' => 'AND',
    		array(
    		        'meta_key' => 'firstinfo',
                            'meta_value' => $till,
    		        'compare' => '=',
    			'type' => 'NUMERIC'
    	         ),
    		array(
                            'meta_key' => 'secondinfo',
                            'meta_value' => $fall,
    			'compare' => 'LIKE'
    		)
    	)
    );
    $theuser = get_users( $args );

    The link to the website —> bv.webkreativ.se. The search form is at the bottom of first page and when you click on “S?K” you will be taken to the search results page where no matter what you choose on the startpage, all users will be listed!

    I really need help with this! Why doesn’t the meta_query work?

Viewing 1 replies (of 1 total)
  • Thread Starter DamirCalusic

    (@webkreativ)

    I solved it finally! it should me key and value and not meta_key and meta_value in the Meta_Query array!

Viewing 1 replies (of 1 total)
  • The topic ‘get_users() meta_query does not work as expected!’ is closed to new replies.