Home Forums ACF PRO Category image from post loop


Category image from post loop

  • Any guidance on this would be great, I’ve been wrestling with this for a couple of days and probably doing something obviously wrong.

    I have an image field assigned to categories called ‘category_logo’.
    I’m trying to display the image on a custom home page template.
    I have the image call in a loop for another category “articles” (id 26).
    I’m trying to retrieve the image from a child category assigned to the post. The parent is “contributors“ (id 11).
    I’m able to retrieve the child category name, but cannot get the image from the custom field.

    <?php global $post;
               $args = array( 'posts_per_page' => 8, 'offset'=> 0, 'category' => 26 );
               $articleposts = get_posts( $args );
               foreach ( $articleposts as $post ) : setup_postdata( $post );
               <a href="<?php the_permalink(); ?>">
               <h6><?php the_title(); ?></h6>
               <?php foreach((get_the_category()) as $childcat) {
                  if (cat_is_ancestor_of(11, $childcat)) { 
                   $childcat_name = $childcat->cat_name;
                   $cont_badge = get_field('category_logo', $childcat_name);?>
                  <img src="<?php echo $cont_badge['url'];?>"><?php echo $childcat_name; ?>
               <?php }};?> 
              <?php endforeach; wp_reset_postdata();?>
Viewing 1 post (of 1 total)

The topic ‘Category image from post loop’ is closed to new replies.