I’m facing an issue filtering on radio button.
I need to set meta_query filter in my request. It’s okay for every field but not for the radios ones.
my ‘licencie’ field send me 2 options : Male or Female.
How can I use this field in a wp_query ? It’s not working with an array and a ‘IN’ comparison, It’s not working with a ‘=’ comparison, .. Does anyone faced this issue ?
PRoblem is that I’m coding a search system.
So there is 3 possibilities :
I’m searching for post who have meta ‘pieds’ set to ‘gauche’ or ‘droite’ for when radio is not checked at all
I’m searching post who have meta pied set to ‘gauche’
I’m searching post who have meta pied set to ‘droite’
How can I do something like this in a meta_query ?
This is simple:
1 / My users have a ‘pieds’ field (radio) which they can set to Gauche / Droite
2 / I have a homemade searchform, and when form is submitted I’m making a wp_query request with args on the post informations.
3 / My ‘pieds’ searchfield is not working, I don’t know how to get users depending on the radio field. What should I put in my wp_query ? I need to use the same request when searchfield is set or no. (If not set get all users, if set get only users where meta is corresponding”
And is it possible with an array ?
like this :
‘meta_query’ => array(
‘key’ => ‘radio_field_name’,
‘value’ => [‘1′,’2’],
‘compare’ => ‘IN’
I need to make it work this way because It’s possible that my user won’t search by this meta_field, so I need to get them all
No, A radio field only has one value
$args = array( // other wp query args 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'radio_field_name', 'value' => 'value you want to search for' ), array( 'key' => 'radio_field_name', 'value' => 'a different value you want to search for' ) ) ); $query = new WP_QUERY($args);
The topic ‘Search on ACF field’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!