Support

Account

Home Forums General Issues Image in category

Solved

Image in category

  • I use this code

    <?php $cover = get_field( 'cover', false, false); ?>
    <?php if ( $cover ) { ?>
    	<img src="<?php echo $cover['url']; ?>" alt="<?php echo $cover['alt']; ?>" />
    <?php } ?>

    in a category template but it doesn’t seem to work. Any clue why?

  • The post ID must be for the category. See the Get a value from different objects section of https://www.advancedcustomfields.com/resources/get_field/

  • I want a featured image for every category and not specific id category.I want to target the current category every time. I’m sorry if I get something wrong

  • Never mind I found the solution. This is the code I used

    <?php $category_id = get_queried_object_id(); ?>
     <?php $cat_id = 'category_'.$category_id; ?>
     <?php $image = get_field( 'cover', $cat_id); ?>
     <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Image in category’ is closed to new replies.