Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Run a check for multiple meta key values

use php’s implode to join array elements with a string:

<?php
if( $bands = get_post_meta($post->ID, 'band') ):
    ?>
    <strong>Band:</strong> <?php echo implode( $bands, ', ' ); ?><br />
    <?php
endif;
?>

EDIT- another version of above, pluralizing the label depending on single or multiple meta values:

<?php
if( $bands = get_post_meta($post->ID, 'band') ):
    $label = count( $bands ) > 1 ? 'Bands' : 'Band';
    ?>
    <strong><?php echo $label; ?>:</strong> <?php echo implode( $bands, ', ' ); ?><br />
    <?php
endif;
?>

Related Posts:

  1. When using add_post_meta and update_post_meta, is there any way to give the individual arrays keys?
  2. Is it possible to store arrays in a custom field?
  3. How to break meta values into different items and avoid duplicates?
  4. Get specific custom field keys from a post and put into an array
  5. How to wrap meta values seperated by comma in ? [closed]
  6. Sort alphabetically by custom field
  7. IF Custom field value equals ZERO
  8. Update post meta custom field using block editor
  9. change order of images attached to post
  10. query_posts with meta_value
  11. Show array of meta_value in Edit Post Coloum
  12. Set class if a meta value is set within post archive
  13. Custom Field: Display only if a specific key is selected outside the loop
  14. How do i output images from URL’s added to the same custom field key
  15. Build Array from Input Fields question
  16. WP Query Args – search by meta_key or title
  17. Saving multiple custom meta box fields
  18. get Custom field label (select/dropdown) on front end
  19. Block Editor – Meta values not saved, meta changes to empty array on update
  20. Custom post meta field effect on the performance on the post
  21. Difference between meta keys with _ and without _ [duplicate]
  22. Orderby meta_value only returns posts that have existing meta_key
  23. What is “meta_input” parameter in wp_insert_post() used for?
  24. How to enable revisions for post meta data?
  25. Can I query custom meta data through WP_Query
  26. How can I display all values of a custom field from posts with a certain value of another custom field or from certain post types?
  27. How do I search an array stored in a custom-field using WP_Query?
  28. Is there a hook / action that is triggered when adding or removing a post thumbnail?
  29. passing argument to get_template_part() or a better way to code
  30. Get updated meta data after save_post hook
  31. Order by custom field date with ASC order
  32. Create meta boxes that don’t show in custom fields
  33. Ordering posts by anniversary using only day and month
  34. use get_posts to get custom field data, but in one array
  35. How to use pagination with get_post_meta
  36. Copying Custom Meta Values from existing post to a duplicate post
  37. WP_query : meta_key with custom rule for specific value
  38. Move value of one custom field to another
  39. Displaying posts with only upcoming dates according their custom field date value
  40. Custom fields: In what order are they saved into the DB?
  41. Get a post_id where meta_value equals something in a serialized meta_value field
  42. How to save a ToggleControl value in a meta field?
  43. MySQL query to set wp_postmeta using term_taxonomy_id value
  44. How to Validate Post Meta type/extension (Video File Image File etc)
  45. Custom Meta Box not Saving in Posts with Gutenberg Editor
  46. How can I sort homepage by a meta value?
  47. How do I use wp_query for WordPress search?
  48. Nav Menu – Add class based on meta keys
  49. Passing Custom Field Data as Array to be Saved (Resulting Custom Field Array is inconsistent)
  50. Bulk remove post meta
  51. How to create html block to display extra information on woocommerce single product page
  52. How to create a Custom Meta Box with Name/Value Admin User Input Fields?
  53. Create Multiple File Upload Metabox in WordPress
  54. Create an Array of Specific Custom Post Meta
  55. Remove Body Classes
  56. WordPress Rest API to call page data associate with custom meta
  57. How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
  58. Hide custom meta data if empty
  59. What WordPress function to use to get meta value by using meta keys?
  60. How to create a shortcode to print specific values stored in a post meta array?
  61. Add custom field to all posts in specific post_type
  62. Button inside Custom Meta Box triggering the Update Button
  63. How to load an assets based on custom field value?
  64. Custom WP_Query for WordPress Search Results with meta_query
  65. How can you include custom post meta in search without calling each key?
  66. Can I access a post meta field before the loop?
  67. wrap text around custom fields array
  68. How can I modify RSS item titles to be either the title or a custom meta field?
  69. Avoiding ACF get_field and returning to core WordPress function
  70. Get all the posts where meta field with multiple choice has several values checked
  71. Move Title and the Content WYSIWYG editor position
  72. List custom field values ​​in alphabetical order without repetition
  73. How do i get the attached images with custom value checked?
  74. WordPress loop by meta key that is an array? and how loop multiple arrays
  75. Print specific values stored in a post meta array
  76. Get custom fields without _edit_last, _edit_lock, _wp_page_template and _visual-subtitle
  77. Display posts with empty custom field
  78. Why am I getting a “Call to member function format() on a non-object” error?
  79. Modify custom field from front end
  80. Footnotes in custom fields
  81. Create a new custom field for all posts based on current custom field
  82. wordpress get_post_meta / the_meta to output custom field value
  83. How to Convert Custom Fields from Text to Array?
  84. Custom Query: query by post custom meta data
  85. Custom field outside the loop and inside an array
  86. update_post_meta not working well
  87. User query – getting values for custom meta keys/fields
  88. How to add a post’s view count into the WordPress API response
  89. Can’t set custom meta fields for a post
  90. Allow HTML in Custom Metabox area
  91. Custom field metabox not showing in back-end
  92. Query Multiple meta
  93. Query postmeta values, and return multiple post_titles for common meta value
  94. When post is updated, custom metadata in text area field is overwritten
  95. Media Attachment Custom Meta Fields not saving in Media Uploader when using jQuery UI Autocomplete
  96. When editing a post with a custom meta box the values aren’t displaying correctly
  97. add_post_meta insert null value into Database
  98. Retrieving custom field as shortcode
  99. Extract array from custom field
  100. save all acf options in one meta_value [closed]
Categories custom-field Tags array, custom-field, meta-value, post-meta
Output dynamic_sidebar into PHP
WordPress Search filter to remove possible script injections

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress