Query is returning an empty array (MySQL / Wordpress)

0

How do I get the values from the meta_value = candidate field of this table.

I'musingthisquery,butit'sreturninganemptyarray.

$resultados2=$wpdb->get_results("SELECT * FROM $wpdb->usermeta WHERE $wpdb->usermeta.meta_key = 'wp_capabilities' AND $wpdb->usermeta.meta_value = 'candidate';");

print_r($resultados2);

I want to retrieve the candidate fields.

    
asked by anonymous 10.02.2017 / 13:39

1 answer

3

LIKE OPERATOR

The array is being returned empty because you are looking for 'candidate' (exactly) and the record actually comes as "a: 1: {s: 9:" candidate "; b: 1;}". LIKE will do an approximate search and will return the records that contain "candidate".

Simply change your query as follows:

$wpdb->usermeta.meta_value LIKE '%candidate%'

The % are wildcards that allow any value before or after the search term to be accepted. You could use % just before and only after the value, but in your case it is necessary to use both.

    
10.02.2017 / 14:31