Setup: I have two templates and use the Genesis Framework hooks to populate them:
The event-page uses ACF fields, among which a select field.
When calling get_field_object
on the single-event-template the values display correctly. When I call get_field_object
on the event-template (i.e. within the loop), no values are returned.
Note that get_field
correctly returns the value of another field in both situations.
Code on both pages:
$eventTypeObject = get_field_object( 'event_type' );
$eventTypeValueArr = $eventTypeObject['value'];
$eventTypeValue = $eventTypeValueArr[ 'value' ];
$eventTypeLabel = $eventTypeValueArr[ 'label' ];
$custom_event_type = get_field( 'custom_event_type' );
?>
<ul>
<li>get_field_object: <?php echo print_r($eventTypeObject) ?></li>
<li>field_object['value']: <?php echo print_r($eventTypeValueArr) ?></li>
<li>field_object['value']['value']: "<?php echo $eventTypeValue ?>"</li>
<li>field_object['value']['label']: "<?php echo $eventTypeLabel ?>"</li>
<li>get_field('custom_event_type'): "<?php echo $custom_event_type ?>"</li>
</ul>
<?php
Output on single-event.php:
get_field_object: Array ( [ID] => 130 [key] => field_5b2a622f49bdc [label] => Soort event [name] => event_type [prefix] => acf [type] => select [value] => Array ( [value] => workshop [label] => Workshop ) [menu_order] => 4 [instructions] => [required] => 0 [id] => [class] => [conditional_logic] => 0 [parent] => 82 [wrapper] => Array ( [width] => [class] => [id] => ) [_name] => event_type [_prepare] => 0 [_valid] => 1 [choices] => Array ( [course] => Cursus [lecture] => Lezing [masterclass] => Masterclass [workshop] => Workshop [custom] => Anders ) [default_value] => Array ( ) [allow_null] => 0 [multiple] => 0 [ui] => 0 [ajax] => 0 [return_format] => array [placeholder] => ) 1
field_object['value']: Array ( [value] => workshop [label] => Workshop ) 1
field_object['value']['value']: "workshop"
field_object['value']['label']: "Workshop"
get_field('custom_event_type'): "Dit is een meesterklas"
field_object['value']: Array ( [value] => workshop [label] => Workshop ) 1
field_object['value']['value']: "workshop"
field_object['value']['label']: "Workshop"
get_field('custom_event_type'): "Dit is een meesterklas"
Output on event-template.php:
get_field_object: 1
field_object['value']: 1
field_object['value']['value']: ""
field_object['value']['label']: ""
get_field('custom_event_type'): "Dit is een meesterklas"
Question: why are the values not returned on the event-template.php page?
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.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.