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);
You must be logged in to reply to this topic.
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!
📣 “ACF Chat Fridays”— Advanced Custom Fields (@wp_acf) January 31, 2023
The ACF team holds their first open office hours this Friday! Come and talk ACF, and ask questions about building sites with the plugin.
We’d love to see you there!
📆 Friday 3rd Feb - 3pm UTC
👉 Register here - https://t.co/3UtvQbE4CU pic.twitter.com/oTwW9K1XQ0
© 2023 Advanced Custom Fields.