With the while loop you can add all of the values to an array ($options
). Then, while looping through values you can check to see if the same value appears in the array(in_array($needle,$haystack)
). If it does, do not add it to the options array.
Then, loop each of your clean values into the select. As I mention in the code, you may want to wrap the loop into a function and cache it, then return the values when you call the function.
This is untested, but should get you there:
<?php
$args = array(
'post_type' => 'page',
'posts_per_page' => '-1',
'meta_key' => 'prix_1',
);
$price_query = new WP_Query( $args );
$options = array();
//Instead of leaving this inside the page, should wrap into a function inside functions.php
if ( $price_query->have_posts() ) {
while ( $price_query->have_posts() ) {
$price_query->the_post();
$field = get_field( 'prix_1' );
if ( ! in_array( $field, $options ) ) {
$options[] = $field; //add to the array
}
} //endwhile
}//endif
?>
<div class="col-lg-3">
<select name="page-dropdown">
<?php if ( ! empty( $options ) ) { //this should no longer have duplicates
foreach ( $options as $option ) { ?>
<option value=""><?php echo $option; ?></option>
<?php } //end foreach
} //endif ?>
</select>
</div>