Support

Account

Home Forums General Issues Search on ACF field

Solving

Search on ACF field

  • Hi,

    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 ?

  • A radio field stores a single value and should not be a problem, you should use 'compare' => '=', or are you talking about some other type of field?

  • 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 ?

  • I don’t understand your search requirements enough to construct a 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”

  • Hey I need answers..

  • I still do not completely understand what you’re doing… I don’t even know enough to ask you questions to help me clarify it for me.

  • Hm..

    simpler :

    How to search on a radio ACF field with WP_Query ?

  • 
    $args = array(
      // other wp query args
      'meta_query' => array(
        array(
          'key' => 'radio_field_name',
          'value' => 'value you want to search for'
        )
      )
    );
    $query = new WP_QUERY($args);
    
  • And is it possible with an array ?

    like this :
    ‘meta_query’ => array(
    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);
    
Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.