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


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 -->
    $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 );
    $args = array(
    'post_type' => 'photo',
    'limit' => '1',
    'posts_per_page' => '1',
    'orderby'   => 'title',
    'order' => 'DESC',
    'tax_query' => array(
    'taxonomy' => 'pcat',
    'field' => 'slug',
    'terms' => $custom_term->slug,
    'orderby'   => 'meta_value',
    'order' => 'DESC',
    'meta_key' => 'cat_image',
    <ul class="third">	
    $loop = new WP_Query($args);
    if($loop->have_posts()) { 
    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>
    	<a href="<?php echo the_permalink(); ?>"><img src="<?php the_field('cat_image'); ?>" alt="<?php echo $catimage['alt']; ?>" width="100%"/></a>
    	<?php echo $catimage; ?></li>
         } ?>
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.