Support

Account

Home Forums General Issues Help With Taxonomies

Helping

Help With Taxonomies

  • I’ll do my best to explain this. I’m not new to development, but WordPress/PHP is still a little new to me. Building a site where I have a field group (Knowledgebase) with three taxonomies (Resource Category, Attached Product, File Type).

    I need to create a loop to display:
    1. The name of the “Attached Product” for that Resource Category.
    2. The posts associated with each product.

    All the custom fields, custom post types, and taxonomies have been created. I’m just struggling to find the right steps to get the code to do what I need it to. Any resources or tips would be appreciated!

    Here is an image of what I’m shooting for:

  • Hi @jeremybdavis,

    Thanks for the post.

    To show the attached product, you can have the following loop:

    <?php 
    
    $terms = get_field('attached_product');
    
    if( $terms ): ?>
    
    	<ul>
    
    	<?php foreach( $terms as $term ): ?>
    
    		<h2><?php echo $term->name; ?></h2>
    		
    
    	<?php endforeach; ?>
    
    	</ul>
    
    <?php endif; ?>

    As for the posts in a particular taxonomy you will need to create a loop to get the posts like so:

    $args = array(
    	'post_type' => 'post',
    	'tax_query' => array(
    		array(
    			'taxonomy' => 'attached_product',
    			'field'    => 'slug',
    			'terms'    => 'product',
    		),
    	),
    );
    $query = new WP_Query( $args );
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Help With Taxonomies’ is closed to new replies.