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; ?>
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.