ACF display posts with custom taxonomy
-
I’m trying to loop through a bunch of posts with a given category via ACF ‘taxonomy’ relationship field. I’ve created the post categories in WP but am unsure why my code isn’t displaying anything.
Here’s what I have:
<!-- all post content to be inside this div --> <div class="lt-inner"> <?php $post_type = 'post'; $taxonomy = 'graphic_assets'; # The post category slug i want to display on this page $terms = get_field('asset_cat'); # The ACF taxonomy field name called 'asset_cat' foreach ($terms as $term) : $args = array( 'post_type' => $post_type, 'posts_per_page' => -1, 'tax_query' => array( array( 'taxonomy' => $taxonomy, 'field' => 'graphic_assets', 'terms' => $term, ), ), ); $posts = new WP_Query($args); ?> <?php if ($posts->have_posts()) : ?> <?php while ($posts->have_posts()) : $posts->the_post(); ?> <!-- want to repeat this format below for however many posts with the looped category --> <div class="lt-item"> <div class="lt-icon"> <!-- ACF file field (image) --> <?php if (get_field('asset_icon')) : ?> <img src="<?php the_field('asset_icon'); ?>" alt=""> <?php endif; ?> </div> <div class="lt-desc"> <span class="file-name"> <!-- ACF text field --> <?php the_field('asset_title'); ?> </span> <br> <!-- ACF file field --> <?php if (get_field('asset_file')) : ?> <span class="file-type"> <a href="<?php the_field('asset_file'); ?> "> download </a> </span> <?php endif; ?> <br> </div> </div> <?php endwhile; ?> <?php endif; wp_reset_query(); ?> <?php endforeach; ?> </div>I’d like to think i’m close, but i rarely use WP as my primary CMS.
Any help would be appreciated!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘ACF display posts with custom taxonomy’ is closed to new replies.