Home › Forums › Front-end Issues › ACF image is showing h and it's not showing in front end.
hi,
My image and alt was working fine before but I just noticed my images and alt is not showing and it’s showing “h”. I didn’t change anything. My backend is showing the image. I’m wondering why is not working. Please see screenshit. This is the code.
<?php
$cat = get_query_var('Category');
$args = array(
'child_of' => $cat,
'orderby' => 'date',
'order' => 'ASC'
);
$categories = get_categories($args);
foreach($categories as $category) {
$image = get_field('cat_thumbnail_image', 'category_'. $category->term_id .'');
echo '<article class="work-wrap">
<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" class="work-img">
<img src="' . $image['url']; ?>" alt="<?php echo $image['alt'] . '">
<h2>'. $category->name . '</h2>
</a>
</article>';
}
?>
what is being returned
$image = get_field('cat_thumbnail_image', 'category_'. $category->term_id .'');
// dump returned value
var_dump($image);
Please answer the question that I asked.
I am attempting to help you figure out why it’s not showing. Your code does not indicate a reason. Debugging is required.
Please see screenshot. It showing the img url. Let me know if u see the screenshot.
This means that you image field is returning the URL of the image. This means that you are expecting it to return an image array $image['url']
Check your field settings to make sure that it is set to return an image array and not the image URL.
Thank you. I change it to return an image array and it works now.
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 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.