Support

Account

Home Forums General Issues ACF relationship field group by taxonomy Reply To: ACF relationship field group by taxonomy

  • Ok I ended up with a solution, here is the code, don’t hesitate to comment!

    						<?php $spes = get_field( 'rel_spes', false, false ); if ( $spes ) : ?>
    
    	<?php 
    		$types = get_terms( array(
    		    'taxonomy' => 'job-type',
    		    'hide_empty' => true,
    		    'object_ids' => $spes 
    			)
    		);
    		
    		foreach( $types as $type ) : 
    		
    		$args = array(
    		    'post_type'         => 'job',
    		    'posts_per_page'    => -1,
    		    'post__in'          => $spes,
    		    'orderby'           => 'post__in',
    			'tax_query' => array(
    				array(
    					'taxonomy' => 'job-type',
    					'terms' => $type->slug,
    					'field' => 'slug',
    				),
    			),							    
    		);
    		$jobs = new WP_Query($args); 
    	?>
    		<p class="widget-title job-types"><?php echo $type->name; ?></p>
    		
    		<ul class="sidebar-menu">
    			<?php foreach( $jobs->posts as $post ) : setup_postdata( $post ); ?>
    			<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    			<?php endforeach; wp_reset_postdata(); ?>
    		</ul>
    		
    	<?php endforeach; ?>
    
    <?php endif; ?>