Support

Account

Home Forums General Issues Custom Post Type Category Image

Solved

Custom Post Type Category Image

  • I have a custom post type for jobs using Simple Job Board plugin. I’m querying the custom post type to list the title of each category and the category featured image. I used ACF to add a field for a category image in the custom post type category settings. I’ve researched everywhere but every solution out there isn’t showing the image. In the console it says img src unknown. The query is working since the category titles are outputting. It’s just the image not showing up. This is the only section where it’s not working since in my archives page, the category images show up there. Here’s my code along with the settings in ACF.

              <div class="inner-row large-up-3 small-up-2">
                <?php
                $taxonomy = 'jobpost_category';
                $terms = get_terms($taxonomy, $args = array(
                  'hide_empty' => false,
                ));
    
                ?>
    
                <?php foreach( $terms as $term ) :
                  $catIMGId = get_field('image', 'jobpost_category_' . $term->term_taxonomy);
                  $catIMG = wp_get_attachment_image_src($catIMGId, 'full', false);
                  ?>
    
                <a class="image-nav-block" id="post-<?php the_ID(); ?>" href="<?php echo get_term_link($term->slug, $taxonomy); ?>">
                  <div class="nav-block-overlay">
                    <div class="title-overlay">
                      <?php echo $term->name; ?>
                    </div>
                    <img src="<?php echo $catIMG[0]; ?>" alt="">
                  </div>
                </a>
              <?php endforeach; ?>
    
              </div>

    ACF Image Settings
    Results

  • 
    $catIMGId = get_field('image', 'term_' . $term->term_id);
    
  • Thanks @hube2! I think it was one of your previous replies that helped me solve my issue prior to you responding to my post. Here’s the full final code for anyone else having issues. Also, the image field in ACF settings is set to Image ID. I have this set to take advantage of WordPress serving up responsive images.

              <div class="inner-row large-up-3 small-up-2">
                <?php
                $taxonomy = 'jobpost_category';
                $terms = get_terms($taxonomy, $args = array(
                  'hide_empty' => false,
                ));
    
                ?>
    
                <?php foreach( $terms as $term ) :
                $catIMG = get_field('job_cat_image', 'jobpost_category_' . $term->term_id);
                ?>
    
                <a class="image-nav-block" id="post-<?php the_ID(); ?>" href="<?php echo get_term_link($term->slug, $taxonomy); ?>">
                  <div class="nav-block-overlay">
                    <div class="title-overlay">
                      <?php echo $term->name; ?>
                    </div>
                    <?php echo wp_get_attachment_image($catIMG, 'medium'); ?>
                  </div>
                </a>
    
                <?php endforeach;?>
    
              </div>
  • Did you manage to do that with Elementor? I am having the same issue. A custom taxonomy’s featured image (under WooCommerce product post type) (field created with ACF) can’t be displayed. Although category’s featured image can be displayed…

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

The topic ‘Custom Post Type Category Image’ is closed to new replies.