How to display custom image field in foreach
-
Hi,
my website has a category page. I want list of subcategories on this page and I want to display – name of subcategory, description of subcategory and image of subcategory. In ACF I added custom image field (the field name is obrazek_podkategorie and it is supposed to return image URL) for categories and now in my template file category.php I have this:
<?php $this_category_id=get_query_var('cat'); $args=array( 'parent' => $this_category_id, 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 0 ); $categories=get_categories($args); foreach($categories as $category) { echo '<img src="'. the_field('obrazek_podkategorie') .'"/>'; echo '<b>'. $category->name .'</b>'; echo '<p>'. $category->description .'</p>';} ?>
[Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]
but it doesn’t work..how can I display the image of subcategory? Can anybody help me pls?
https://www.ads-software.com/extend/plugins/advanced-custom-fields/
- The topic ‘How to display custom image field in foreach’ is closed to new replies.