Home › Forums › Front-end Issues › Count field selection in a WP Query › Reply To: Count field selection in a WP Query
What about something like:
<?php
if($filter_price):
echo '<select name="sort_price" id="sort_price">';
echo '<option value="" selected disabled>Select...</option>';
echo '<option value="">All</option>';
foreach($filter_price as $price):
echo '<p>Price: '.$price.'</p>';
$args = array(
'post_type' => 'cars',
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'price',
'value' => $price,
'compare' => '<='
),
)
);
$wp_query = new WP_Query($args);
$figure_total = $wp_query->found_posts;
$count = count( $wp_query->get_posts() );
#echo '<p>$figure_total: '.$figure_total.' count: '.$count.'</p>';
$round_price = round($price, -3);;
echo '<option value="'.$round_price.'">Up to £'.$round_price.' ('.$count.')</option>';
wp_reset_query();
endforeach;
echo '</select>';
endif; #endif $filter_price
Again, untested code so may error or need some tweaking!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.