Support

Account

Home Forums Front-end Issues ACF Taxonomies : Get just the used Terms in a DropDown

Unread

ACF Taxonomies : Get just the used Terms in a DropDown

  • Hi

    I haven’t found an answer to my question yet …

    I’m looking for a solution to list “Terms” used in custom post in a dropdown (Name + Link).

    I created an ACF Taxonomy like on the screenshot below.

    From my custom post I chose the main Term (1 only) which will be displayed on my thumbnails in my list (Archive).

    I tried a loop here, I have the 10 terms used on all of my CPTs but the names and links are not displayed.

    					  <?php 
    					  	$taxonomies = get_field('thematique');
    					  	
    					  	// args
    					  	$args = array(
    					  		'numberposts' => -1,
    					  		'post_type' => 'portfolio',
    					  		'tax_query' => array(
    					  			array(
    					  				'taxonomy' => 'categoriesportfolio',
    					  				'field' => 'motscles',
    					  				'terms' => array()
    					  			),
    					  		)
    					  	);
    					  	
    					  	if( $taxonomies )
    					  	{
    					  		foreach( $taxonomies as $term )
    					  		{
    					  			$args['tax_query']['terms'][] = $term->name;
    					  			$term_list .= '<a href="' . esc_url( get_term_link( $term ) ) . '" alt="' . esc_attr( sprintf( __( 'View all post filed under %s', 'my_localization_domain' ), $term->name ) ) . '" class="dropdown-item" >' . $term->name . '</a>';
    					  		}
    
    						 echo $term_list;
    
    					  	}
    
    					  	// get results
    				  		$the_query = new WP_Query( $args );
    					  
    					  	?>

    Thanks for your help ! 🙂

Viewing 1 post (of 1 total)

The topic ‘ACF Taxonomies : Get just the used Terms in a DropDown’ is closed to new replies.