Home › Forums › General Issues › How to get the selected values only from a select field? › Reply To: How to get the selected values only from a select field?
You need to do a query of all of the posts where this field is used and then loop through all of the posts to collect a list of the values that are actually used. The only place that information is stored is in the _postmeta table related to each post.
For example:
global $post;
$cities = array();
$args = array(
'post_type' => 'page',
'posts_per_page' => -1
)
$query = new WP_Query($args);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$city= get_field('city-field-name');
if (!in_array($cities)) {
$cities[] = $city;
}
}
}
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.