Home › Forums › Front-end Issues › How to display field labels and values
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
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.
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!
We’re reaching out to our multilingual users to ask for help in translating ACF 6.1. Help make sure the latest features are available in your language here: https://t.co/TkEc2Exd6U
— Advanced Custom Fields (@wp_acf) May 22, 2023
© 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.