Home › Forums › Front-end Issues › Retrieve all field options in admin
Hey,
i’m looking for a way to retrieve all choices setup in the admin for a specific field and not relative to a post/page.
Something like get_field_object(null, $field_name/$field_key)
.
null
would be to indicate that it is not a search for a specific post/page.
get_field()
seems to do the job with the Get a value from different objects section but without luck so far.
get_fields()
get_field_objects()
and get_field_object()
all default to current post ID if not specified.
WP: 4.8
ACFPro: 5.3
try ‘get_field_object($field_key)` but this will also default to the current post id. But the choices should be the same for all fields, shouldn’t they?
you can also try acf_get_field($field_key)
which is an internal ACF function that is used for getting a specific field.
Hey John,
acf_get_field()
sounds good but still not the right values. After investigation, here’s what i discovered:
When used in my theme file header.php acf_get_field retrieves those choices:
[choices] => Array
(
[casa] => Casa
[apartamento] => Apartamento
[loft] => Loft
[cobertura] => Cobertura
[duplex] => Duplex
[beiramar] => Beira-Mar
)
and when using the Export Field Groups to PHP tool in the admin, here’s what i get:
'choices' => array (
'ap' => 'AP',
'apartamento' => 'Apartamento',
'loft' => 'Loft',
'cobertura' => 'Cobertura',
'duplex' => 'Duplex',
'fazenda' => 'Fazenda',
'beiramar' => 'Beira-Mar',
'haras' => 'Haras',
'andar' => 'Andar',
'sala' => 'Sala',
'terreno' => 'Terreno',
),
All the choices.
Crazy thing, [key]
and [name]
are identical.
Any reason you could think of that would trigger this behavior?
the only thing that I can think of is that you have a filter created for this field that is altering the choices.
The topic ‘Retrieve all field options in admin’ 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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.