Support

Account

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.