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

  • Thank you for this code! It has helped with categorization, however, I am having an issue. It is not listing the correct titles under each category. Instead it’s categorizing from the relationship field but when I do the_title(); it is repeating the curent page’s title.

    Custom post types named solutions and services. Services has taxonomy service_type attached.

    In solutions, I have created a relationship field called related_services.

    Below code is in the template for solutions page. Any idea what I might be doing 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(
    				'taxonomy' => 'service_type',
    				'terms' => $type->slug,
    				'field' => 'slug',
    		$svc = new WP_Query($args); ?>
    		<p class="widget-title service_types"><?php echo $type->name; ?></p>
    		<ul class="sidebar-menu">
    		<?php foreach( $svc->posts as $post ) : setup_postdata( $post ); ?>
    			<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    		<?php endforeach; wp_reset_postdata(); ?>
    	<?php endforeach; ?>
    <?php endif; ?>