Support

Account

Home Forums General Issues Retrieve all possible field options

Solved

Retrieve all possible field options

  • I’ve got a custom post type that has an ACF meta box set up for it. On the CPT’s archive page, I would like to retrieve all possible options for a few specific fields. For example, one field is a radio list with 5 options for the number of employees. I know how to get the answer of the field for each post, but I’m wondering how I can get specify a field and get all of the possible options outside of the loop. Then display that data in a sidebar.

    The whole purpose for this is to allow some simple filtering, but I can’t figure out how to pull back the data I want.

    Any help appreciated, thanks!

  • I think you need to use get_field_object but don’t quote me – I’m learning as well. 🙂

    $choices = get_field_object('yourFieldKey');

    http://www.advancedcustomfields.com/resources/functions/get_field_object/

  • Hi @cmegown

    Yes, just use the get_field_object to find the $field array. Within that array you will see the field’s choices.

    This function uses a $field_name parameter, but you may also need to specify a $post_id parameter of a post where this field has saved a value. If this is not possible, please use the $field_key instead of the $field_name.

    Thanks
    E

  • Thanks @Will and @elliot, both answers solved my issue!

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Retrieve all possible field options’ is closed to new replies.