Current status: Solved. . Done
[Solved] Get all options from a drop down field, not just the selected one?
  • I understand how to get the option that a user selects in a drop-down. Is it possible to get all the options from a drop down?
  • Ok if anyone needs something like this, I did it this way:

    $results = get_pages(array(
    'numberposts' => -1,
    'post_type' => 'acf',
    'sort_column' => 'menu_order',
    'order' => 'ASC',
    ));

    //You'll need to find the corresponding key created by ACF and plug it into the first parameter. You should be able to find this with print_r($results);

    $field = $acf->get_acf_field("field_4ff72cd781b1d", $results[0]->ID);

    //get an array of all choices in a drop down.
    print_r($field['choices']);

    Hope this helps!
  • CORRECTION:

    To find the key, use print_r($acf->get_field_groups());
  • You saved my day! Big ups.

    added this to get only the value if someone not into php finds this.

    foreach ($field['choices'] as $i => $value) {
    echo $i;
    }
  • For anyone stumbling upon this question you can use get_field_object() to find the options in a select menu.
    $field_obj = get_field_object( 'field_506d7b9428874', $post_id_where_field_is );


    If you take a look at the returned $field_obj array using var_dump( $field_obj ) you will find the select menu options under 'choices'.

    You should be able to access the options like this:
    foreach ( $field_obj['choices'] as option ){
    echo option // Prints out the option
    }