Support

Account

Home Forums General Issues Post Object with Multiple Select Reply To: Post Object with Multiple Select

  • Thanks @elliot for the reply.

    I believe I’ve solved it. I’ve used the below to do what I need, not sure if there is a cleaner way though:

    <ul>
    <?php	
    $args = array( 
    	'post_type' => 'job_sectors',
    	'post_status' => 'publish',
    	'order'    => 'ASC',
    	'orderby'	=> 'name'
    );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
    
    ?>			
    	<li><a href="<?php echo get_permalink($pageChild->ID);?>" title="<?php the_title(); ?>"><?php the_title(); ?><?php #the_ID(); ?></a>	
    	<?php
    	global $post;
    	$args = array(
    		'post_type' => 'jobs',
    		'meta_query' => array(
    			array(
    				'key' => 'job_sector',
    				'value' => get_the_ID(),
    				'compare' => 'LIKE'
    			)
    		)
    	);
    	
    	$myposts = get_posts( $args );
    	$total = 0;
    	foreach( $myposts as $post ) : 
    	$total = $total + $post; 
    	?>
    	
    	<?php endforeach; 
    	wp_reset_postdata(); 
    	echo "($total)"; 
    	?>
    	</li>
    
    <?php endwhile; ?>			
    </ul>

    Thanks