Support

Account

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; ?>