Home › Forums › Front-end Issues › Pulling values from taxonomy array › Reply To: Pulling values from taxonomy array
Hi Kyle,
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.