Support

Account

Home Forums ACF PRO Show ACF field in Custom Post Type query

Unread

Show ACF field in Custom Post Type query

  • I have a custom post type ‘photo’
    and custom taxonomy ‘pcat’

    Currently I’m using a Query to show the CPT category names.
    I would like to add in an image to go with the Category names.

    I have created an ACF group to add the image to the category ‘cat_image’, but I can’t get it to display yet?
    How do I get ‘cat_image’ and display it by the category name?

    <!-- get custom posts and categories -->
    <?php 
    
    $custom_terms = get_terms('pcat', 'orderby=count&order=DESC&hide_empty=1');
    foreach($custom_terms as $custom_term) {
    $custom_link = get_term_link( $custom_term );
    wp_reset_query();
    
    $args = array(
    'post_type' => 'photo',
    'limit' => '1',
    'posts_per_page' => '1',
    'orderby'   => 'title',
    'order' => 'DESC',
    'tax_query' => array(
     array(
    'taxonomy' => 'pcat',
    'field' => 'slug',
    'terms' => $custom_term->slug,
    'orderby'   => 'meta_value',
    'order' => 'DESC',
    'meta_key' => 'cat_image',
     ),
     ),
     );
     ?>  
    <ul class="third">	
    <?php
    $loop = new WP_Query($args);
    if($loop->have_posts()) { 
    ?> 
    
    <?php 
    while($loop->have_posts()) : $loop->the_post();
    
    ?>
    
    <li><h2 class="cat-title"><a href="<?php echo $custom_link; ?>"><?php echo $custom_term->name; ?></a></h2>
    <figure>
    	<a href="<?php echo the_permalink(); ?>"><img src="<?php the_field('cat_image'); ?>" alt="<?php echo $catimage['alt']; ?>" width="100%"/></a>
    	</figure>
    	<?php echo $catimage; ?></li>
    
    <?php
            endwhile;
         } ?>
    
    <?php
    }
    ?>
    </ul>		
Viewing 1 post (of 1 total)

The topic ‘Show ACF field in Custom Post Type query’ is closed to new replies.