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
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.