Support

Account

Home Forums Front-end Issues Taxonomy-based image field not generating URL

Solving

Taxonomy-based image field not generating URL

  • I have set up an image field for categories within a site. So far I have been able to make it return only “h” when echoing the image URL. Based on this article I have tried the following two approaches in the category.php template:

    <div class="posthead-blockimg r">
     <?php 
      $term = get_queried_object();
      $image = get_field('category_image', $term);
     ?>
     <?php if( $image ): ?>
      <img src="<?php echo $image['url']; ?>">
     <?php endif; ?>
    </div>
    <div class="posthead-blockimg r bgimg">
     <?php 
      $term = get_queried_object();
      $image = get_field('category_image', $term);
     ?>
     <style type="text/css">
      <?php if( $image ): ?>
       .bgimg {
        background-image: url(<?php echo $image['url']; ?>);
       }
      <?php endif; ?>    
     </style>
    </div>

    Obviously I am expecting to see the image in the resulting category page, but am simply getting an empty frame, as the code returned remains:

    <div class="posthead-blockimg r">
     <img src="h">
    </div>

    Ideally I’d like to be calling the image ID rather than the image URL, as I’d like to specify image size, too.

    The page with no image is here.

    Anyone any idea what I’ve done wrong here?

  • Hi @mtm,

    Did you get this sorted? I can’t find that particular markup on the page you linked but your code is correct / works a-okay on my end.

  • thanks @allisonplus, no i didn’t get this fixed as in the end the build took me in a different direction and i didn’t need it for this specific project, but it’s helpful to know you think the code is correct. i’m sure i’ll need to do this at some point in the future so i guess i’ll see whether next time i have the same problem!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.