I'm using Verve Meta Boxes. I want to make a menu out of one of the custom fields. How can I return all of the custom field values? For example, if I had a custom select field called "fruit" and as options I have "apples", "oranges", and "bananas", how could I get a complete list of those values, as an array perhaps? I can get the ones associated with a post:
get_post_custom_values('fruit')
…but I can't work out how to get the whole list.
Thank you in advance!
To add a Custom Field, type in the Key (labeled “Name”) and Value, then click Add Custom Field. After it's added, you can delete or update it from buttons below the Key/Name: After you have used Custom Fields, the keys will form into a dropdown menu for easier selection.
get_post_custom_values( string $key = '', int $post_id ): array|null. Retrieve values for a custom post field.
To export WordPress custom fields to CSV/XML go to WP All Export › New Export and select the post type you'd like to export. WP All Export will automatically detect the custom fields from your posts. Drag and drop to select fields to export, arrange the spreadsheet columns, and more.
In case someone still wondering:
global $wpdb;
$results = $wpdb->get_results( 'SELECT DISTINCT meta_value FROM wp_postmeta WHERE meta_key LIKE "FIELD_NAME"', OBJECT );
Just make sure your postmeta table is "wp_postmeta" (default) and change FIELD_NAME with the name you created for the field in the admin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With