Home › Forums › Front-end Issues › cant see the fields on the front
hi
im using this code but gett null, help please:
<?php
$values = get_field(‘field_name’);
if($values)
{
echo ‘
foreach($values as $value)
{
echo ‘
‘;
}
echo ‘
‘;
}
// always good to see exactly what you are working with
var_dump($values);
?>
We need more information about your code in order to help you. What type of field is it? what do you get when you dump $values; Is this code on a templates page? Are you including it within the loop? Are you pulling it from a different post or user?
I would also suggest in the future to use “\n” for line returns rather than physical line returns in apostrophes.
hi and thanks for your reply..
i solved the problem, but when i use texampny fiels or select i get display “Array”, how can i fixed it please ?
this is my code:
<?php
$fields = get_fields();
if( $fields ): ?>
<div class=”fields_name”>
<?php foreach( $fields as $name => $value ): ?>
<?php if ($value != ”){ ?>
<?php $string = $name;
$result = preg_replace(‘/_/’,’ ‘, $string);?>
<p><b><?php echo “<i style=’color:black;padding-left:10px;’ class=’fas fa-check-square’></i><span class=’name_lable’>” .$result; ?>:</span></b> <?php echo “<span class=’name_value’>” .$value; ?></span></p>
<?php }?>
<?php endforeach; ?>
</div>
<?php endif; ?>
This is because it is returning an array. You may want to read up on the documentation for each field to see how the arrays are formed
https://www.advancedcustomfields.com/resources
thanks for your answere.. can you help me to add the code of the array to my code above ?
thank you
hi
i will be grateful if someone will help me to combine the two code of array and simple fiels value… thanks
What type of field are you dealing with?
The documentation that @djcottrell pointed you to for each field gives example code for dealing with all of the different return values.
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!
🚨 The 2023 ACF Annual Survey closes tomorrow! This is your last chance to complete the survey and help guide the evolution of ACF. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 18, 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.