Home › Forums › General Issues › ACF relationship field group by taxonomy › Reply To: ACF relationship field group by taxonomy
Thank you for the code. I plugged that in and made changes as necessary and got it to work except listing the titles. It is listing the current page titles over and over instead of from the relationship field.
Do you know where I might have gone wrong?
$avail_services = get_field( 'related_services', false, false );
if ( $avail_services ) {
$types = get_terms( array(
'taxonomy' => 'service_type',
'hide_empty' => true,
'object_ids' => $avail_services
)
);
foreach( $types as $type ) {
$args = array(
'post_type' => 'services',
'posts_per_page' => -1,
'post__in' => $avail_services,
'orderby' => 'post__in',
'tax_query' => array(
array(
'taxonomy' => 'service_type',
'terms' => $type->slug,
'field' => 'slug',
),
),
);
$svc = new WP_Query($args);
echo '<h2>'.$type->name.'</h2>';
echo '<ul class="sidebar-menu">';
foreach( $svc->posts as $post ) { setup_postdata( $post );
echo '<li>'.get_the_title().'</li>';
};
wp_reset_postdata();
echo '</ul>';
};
};
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.