Support

Account

Home Forums General Issues merge contents of 2 subfields to one result Reply To: merge contents of 2 subfields to one result

  • This may be close, but i may not be understanding it. My main cpt is the event, so I thought that I would be querying that post. so say i wanted to see all the speakers (both normal and frontpage) from the most recent event…

    I was thinking something like this:

    $query = new WP_Query( 
    		array( 
    			'post_type' => 'events', 
    			'posts_per_page' => '1', 
    			'order' => 'DESC',
    		)
    	 );
            $count = $query->post_count;
            $i = 1;
    while ( $query->have_posts() ) : $query->the_post();
        $speakers = array_merge(
             get_field('relationship_1', false, false),
             get_field('relationship_2', false, false));
        if($speakers): 
           echo '<ul>';
    	foreach( $speakers as $speaker ):
                echo '<li>'.get_the_title($speaker -> ID).'</li>';
    	    $i++;	
    	endforeach;
    	 echo '</ul>';
    
    endif;
    endwhile;
    
    wp_reset_postdata();
    
    ?>

    does that make sense?