Home › Forums › Front-end Issues › Count field selection in a WP Query › Reply To: Count field selection in a WP Query
Try adding some debugging to the code, see what outputs you get at the various stages:
<?php
$args = array(
'post_type' => 'cars',
'posts_per_page' => -1,
'post_status' => 'publish',
'meta_query' => array(
'post_type' => 'cars',
'post_per_page' => -1,
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'sold',
'value' => array('no'),
'compare' => 'IN',
),
)
)
);
$wp_query = new WP_Query($args);
if ($wp_query->have_posts()) :
$get_price = array();
while ($wp_query->have_posts()) : $wp_query->the_post();
$get_price[] = get_field('price');
endwhile;
endif; #endif $wp_query
echo '<pre>';
print_r($get_price);
echo '</pre>';
$filter_price = array_unique($get_price);
echo '<pre>';
print_r($filter_price);
echo '</pre>';
if($filter_price):
foreach($filter_price as $price):
echo '<p>Price: '.$price.'</p>';
$args = array(
'key' => 'price',
'value' => $price,
'type' => 'numeric',
'compare' => '<=',
);
$wp_query = new WP_Query($args);
$figure_total = $wp_query->found_posts;
echo $figure_total;
endforeach;
endif; #endif $filter_price
So first thing is see what the main array gets
Then see what the filtered results returns
When you then loop the filtered array, output the values as a heading
I did just adjust the query in the foreach, as mentioned, I’ve not tested the code, just trying to cobble it together as a starting point.
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!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN
— Advanced Custom Fields (@wp_acf) March 2, 2023
© 2023 Advanced Custom Fields.
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.