Hello,
I’m now spending hours on this problem. I try to display a field label and with the according value.
Please can someone advise how you go about displaying the field value?
Kind Regards,
Janson
Here is my code:
<?php
$field_key = "field_553a0e58f395d";
$fields = get_field_object($field_key);
if( $fields ): ?>
<?php echo $fields['label']; ?><?php echo $fields['value']; ?>
<?php endif; ?>
At my Website I can only see the label field but not the value.
I am using this code to display the flexible content field.
This is the main code:
<?php while(has_sub_field("produktion")): ?>
<?php if(get_row_layout() == "einleitung_mit_überschrift"): ?>
<div class ="er">
<?php the_sub_field("überschrift"); ?>
<?php the_sub_field('textfeld'); ?>
</div>
<hr>
<?php elseif(get_row_layout() == "text_mit_überschrift"): ?>
<div class="headline-box-1">
<?php the_sub_field("überschrift"); ?>
</div>
<?php the_sub_field('textfeld'); ?>
<hr>
<?php elseif(get_row_layout() == "video"): ?>
<div class="er">
<?php the_sub_field("link_zum_video"); ?>
</div>
<?php
$field_key = "field_553a0e58f395d";
$fields = get_field_object($field_key);
if( $fields ): ?>
<?php echo $fields['label']; ?><?php echo $fields['value']; ?>
<?php endif; ?>
<?php elseif(get_row_layout() == "galerie"): ?> <!-- Gallery Field -->
<?php $images = get_sub_field('bilder');
if( $images ): ?>
<div id="slider" class="flexslider">
<ul class="slides">
<?php foreach( $images as $image ): ?>
<li>
<img src="<?php echo $image['url']; ?>"/>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<?php endif; ?>
<?php endwhile; ?>
Hello iam stuck with the same issue; have you found out?
thank you, sonia
Hi @janson and @soniadm
The code seems to be working just fine. You can also check out the original sample here
https://www.advancedcustomfields.com/resources/get_field_object/
I hope this helps.