Support

Account

Home Forums General Issues Get DISTINCT values for all posts Reply To: Get DISTINCT values for all posts

  • Could you use something like the below:

    	$args = array(
    		'numberposts'	=> -1,
    		'post_type'		=> array('post', 'page'),
    		'meta_key'		=> 'colours', // your existing colur select field
    	);
    
    	// query
    	$the_query = new WP_Query( $args );
    	if( $the_query->have_posts() ):
    		$colours = array();
    		while( $the_query->have_posts() ) : $the_query->the_post();
    		$colours[] = get_field('colours');
    		endwhile;
    	endif;
    
    	// remove duplicates
    	$filtered_colours = array_unique($colours);
    	
    	if ( $filtered_colours ) :
    	
    
    		foreach ( $filtered_colours as $colour ) :
    			echo $colour;
    		endforeach;
    	endif;

    Depends on how you need to show/use the values I guess