Home › Forums › General Issues › Get a field object outside of the post context › Reply To: Get a field object outside of the post context
My suggestion would be to go straight to the database to get the values with a custom query to get the available languages. The reason why is that the only way you’re going to populate that list otherwise would be to do a second WP_Query to get every post on your site then loop through them and get the language value for every post and build an array of values.
$query = 'SELECT DISTINCT meta_value
FROM ' . $wpdb->postmeta.'
WHERE meta_key = "language"
ORDER BY meta_value';
$results = $wbdb->get_col($query);
That should return an array of languages set for all posts on your site.
I’m not using prepare above because there are no user inputted values and the query should be safe.
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.