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. SQL query based on two different custom field values
  20. Block Editor – Meta values not saved, meta changes to empty array on update
  21. Can I exclude a post by meta key using pre_get_posts function?
  22. Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
  23. Max length of meta_value
  24. Custom post meta field effect on the performance on the post
  25. How to get custom post meta using REST API
  26. Difference between meta keys with _ and without _ [duplicate]
  27. Orderby meta_value only returns posts that have existing meta_key
  28. What is the index [0] for on post meta fields?
  29. What is “meta_input” parameter in wp_insert_post() used for?
  30. How to enable revisions for post meta data?
  31. The “_encloseme” Meta-Key Conundrum
  32. Best way to programmatically remove a category/term from a post
  33. Using get_post_meta with new_to_publish
  34. Can I query custom meta data through WP_Query
  35. SELECT max(meta_value) FROM wp_postmeta WHERE meta_key=’price’… stops working when value is over 999
  36. Custom field metabox not showing in back-end
  37. So much data in postmeta
  38. Can I count the number of users matching a value in a multiple value key?
  39. How to hide meta box values from custom fields list?
  40. Auto sort the wp-admin post list by a meta key
  41. WP doesn’t show Array Custom Fields?
  42. get_post_meta() unserialize issue – returns boolean(false)
  43. What is the advantage of the wp_options design pattern?
  44. Storing meta fields multiple times OR once with multi dimensional array?
  45. 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?
  46. Allow user to create instances of custom field
  47. display specific custom fields
  48. How do I search an array stored in a custom-field using WP_Query?
  49. Is there a hook / action that is triggered when adding or removing a post thumbnail?
  50. get_pages sort alphabetically by meta value
  51. Meta keywords and descriptions plugin for manually editing meta for each page/post
  52. passing argument to get_template_part() or a better way to code
  53. Get updated meta data after save_post hook
  54. Multiple meta values for same meta_key adding on “Preview Changes” hit but not on saving or updating post
  55. Save HTML formatted data to post meta using add_post_meta()
  56. importing data from non-wordpress mysql db
  57. Assign/update the custom field value for all posts
  58. Order by custom field date with ASC order
  59. Create meta boxes that don’t show in custom fields
  60. Transients vs CRON +Custom Fields: Caching Data Per Post
  61. Unable to save datetime custom meta field using update_post_meta() function
  62. Up/Down voting system for WordPress
  63. post meta data clearing on autosave
  64. Create custom field on post draft or publish?
  65. Display info from custom fields in all images’ HTML
  66. Ordering posts by anniversary using only day and month
  67. get_post_meta fields don’t show up on posts page
  68. Update meta values with AJAX
  69. use get_posts to get custom field data, but in one array
  70. copy attachments to another post type and change attachment url
  71. Cannot edit post meta fields with rest API
  72. ajax delete value from custom field array
  73. Save attachment custom fields on front end
  74. How to use pagination with get_post_meta
  75. Copying Custom Meta Values from existing post to a duplicate post
  76. Add a post meta key and value only if it does not exist on the post
  77. WP_query : meta_key with custom rule for specific value
  78. Saving an array in a single custom field
  79. Move value of one custom field to another
  80. Order posts according to user defined order for meta values?
  81. Displaying posts with only upcoming dates according their custom field date value
  82. Custom fields to save multiple values
  83. Custom fields: In what order are they saved into the DB?
  84. Function to change meta value in database for each post
  85. Get a post_id where meta_value equals something in a serialized meta_value field
  86. Get aggregate list of all custom fields for entire blog
  87. Transition from (classical) serialized custom meta field to (gutenberg) rest enabled meta
  88. Unable to show ACF’s Image Custom Field properly in Genesis Framework [closed]
  89. Custom field value based on other custom field values
  90. wp_handle_upload error “Specified file failed upload test” but still creates attachment?
  91. How to save a ToggleControl value in a meta field?
  92. Which is best in the following scenario : post_meta vs custom table vs parent/child posts
  93. Saving custom image meta fields
  94. Author Page Custom Query WHERE author OR [post meta value] OR [post meta value]
  95. How to display Meta Field Value?
  96. MySQL query to set wp_postmeta using term_taxonomy_id value
  97. How to Validate Post Meta type/extension (Video File Image File etc)
  98. Get all meta keys assigned to a post type
  99. How to sort category by custom field value
  100. trim custom field text value and show (…)
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
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 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