Thanks for the additional explanation. Drop this into the code (within the loop) and give this a shot real quick to see if this outputs the category name and slug correctly. If so, you can then take the ‘category slug’ to generate a custom WP Query to grab the 5 most recent posts by category. If this doesn’t work it’s because I grabbed it from my code and attempted to modify it for your purposes without actually testing… : )
Just let me know if it doesn’t work and I’ll see what I can do. Here’s the code snippet:
<?php $categories = get_the_terms( $post->ID, 'category' ); if ( $categories && ! is_wp_error( $categories ) ) : ?> <ul> <?php foreach ( $categories as $category ) : ?> <li>Category Name: <?php echo $category->name; ?> / Category Slug: <?php echo $category->slug; ?></li> <?php endforeach; ?> </ul> <?php endif; ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
2022 was a big year for Advanced Custom Fields, with more capabilities, a new generation of ACF Blocks, a refreshed UI, and a new home. Our year in review post looks at advancements we’ve made and offers a glimpse of the future.— Advanced Custom Fields (@wp_acf) January 6, 2023
© 2023 Advanced Custom Fields.