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!
🚀 This week’s session of ACF Chat Fridays dips into the preliminary results of our first ever user survey. Don’t miss it! https://t.co/3UtvQbDwNm pic.twitter.com/kMwhaJTkZc— Advanced Custom Fields (@wp_acf) May 9, 2023
© 2023 Advanced Custom Fields.