Home › Forums › Front-end Issues › Make a list of cities from custom fields › Reply To: Make a list of cities from custom fields
The best way to do this would be using a taxonomy for city instead of a text field.
Or you can query the database directly.
// replace city below with your meta key
global $wpdb;
$date = date('Y-m-d H:i:s');
$query = 'SELECT DISTINCT meta_value
FROM '.$wpdb->postmeta.' pm
WHERE pm.meta_key = "city"
ORDER BY pm.meta_value';
$values = $wpdb->get_results($query, 'ARRAY_A');
See documentation for $wpdb here https://codex.wordpress.org/Class_Reference/wpdb
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.