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

If metabox has content display content

You have to list the keys of the meta fields saved in the metabox, because their is no function to dynamically retrieve all the fields saved in specific metabox. For example:

$store_openingtimes_keys = array(
  '_cmb_open_monday', '_cmb_open_tuesday', '_cmb_open_wednesday', '_cmb_open_thursday',
  '_cmb_open_friday', '_cmb_open_saturday', '_cmb_open_sunday'
);
// all the not empty meta for the post
$meta = array_filter( get_post_custom($post->ID) );
// there are any not empty meta that is one of the store opening times?
$times_meta = array_intersect( array_keys($meta), $store_openingtimes_keys );
if ( ! empty($times_meta) ) { // if so, show content
   echo $content;
}

Related Posts:

  1. What is the index [0] for on post meta fields?
  2. Custom field metabox not showing in back-end
  3. How to hide meta box values from custom fields list?
  4. Create meta boxes that don’t show in custom fields
  5. Custom fields to save multiple values
  6. wp_handle_upload error “Specified file failed upload test” but still creates attachment?
  7. Create Multiple File Upload Metabox in WordPress
  8. Button inside Custom Meta Box triggering the Update Button
  9. Why is my Custom Meta Box Field Inputs NOT saving?
  10. get_posts in meta box dropdown not showing latest posts
  11. How can you include custom post meta in search without calling each key?
  12. Display Custom Meta Box Field Only If Value is Present
  13. shortcode in a custom metabox
  14. Problem with saving large amount of data in postmeta/usermeta
  15. Move Title and the Content WYSIWYG editor position
  16. How to validate select field in post meta?
  17. How to use media upload on metabox post page without breaking TinyMCE?
  18. Let’s Create Custom Field Template Documentation
  19. How add multiple wp_editor_box to new post
  20. Can I save post meta programatically without setting metaboxes?
  21. Meta box values are displayed on Custom Fields list. Is it possible to hide them?
  22. put saved metabox values back into fields and then display on the front end
  23. How to improve my non-unique metadata MySQL entries?
  24. Set class if a meta value is set within post archive
  25. WordPress Blocks, setAttributes not saving
  26. Allow HTML in Custom Metabox area
  27. Custom field metabox not showing in back-end
  28. Save, update, get and sanitize post meta as HTML not plain
  29. Create Meta boxes dynamically
  30. Get meta value when the page is a blog archive
  31. Can’t save meta field value if the title not set
  32. Display Data From This Custom Media Upload Meta Box?
  33. When post is updated, custom metadata in text area field is overwritten
  34. wp_postmeta are updated for only one page
  35. When editing a post with a custom meta box the values aren’t displaying correctly
  36. How to add new Metadata options (Date, Author, etc.) for Posts?
  37. Saving multiple custom meta box fields
  38. Can I exclude a post by meta key using pre_get_posts function?
  39. Custom post meta field effect on the performance on the post
  40. How to get custom post meta using REST API
  41. Custom field/meta populated by dropdown of existing posts?
  42. Difference between meta keys with _ and without _ [duplicate]
  43. Orderby meta_value only returns posts that have existing meta_key
  44. What is “meta_input” parameter in wp_insert_post() used for?
  45. How to enable revisions for post meta data?
  46. The “_encloseme” Meta-Key Conundrum
  47. Individual Widgets per Page
  48. Best way to programmatically remove a category/term from a post
  49. Gutenberg add a custom metabox to default blocks
  50. ‘Preview Changes’ for custom meta boxes?
  51. Using TinyMce with textareas in meta boxes on custom post types
  52. Using get_post_meta with new_to_publish
  53. add meta box – custom field : which to choose?
  54. Add metabox to document tab in gutenberg
  55. How to add add_meta_box to specific Page Template?
  56. So much data in postmeta
  57. Can I count the number of users matching a value in a multiple value key?
  58. When using add_post_meta and update_post_meta, is there any way to give the individual arrays keys?
  59. Auto sort the wp-admin post list by a meta key
  60. Adding another state (spam, reject, approve) to wordpress comments?
  61. get_post_meta() unserialize issue – returns boolean(false)
  62. What is the advantage of the wp_options design pattern?
  63. Arrange custom fields with drag and drop?
  64. Storing meta fields multiple times OR once with multi dimensional array?
  65. How can I avoid re-inventing the Custom Fields wheel in my Plugin’s Metabox?
  66. Unable to get Preview of Uploaded image within a Custom Meta box
  67. Allow user to create instances of custom field
  68. Using media-upload.php to upload mp3 via custom fields
  69. extend Meta Box / Document Panel
  70. display specific custom fields
  71. Save metabox with multiple checkbox array
  72. Is there a hook / action that is triggered when adding or removing a post thumbnail?
  73. Add custom option to Standard Page Attributes Meta Box
  74. How to store the value of a custom field dropdown select for post referencing?
  75. Add multiple images to a page sidebar
  76. Meta keywords and descriptions plugin for manually editing meta for each page/post
  77. passing argument to get_template_part() or a better way to code
  78. Only show metabox when date-value in other metabox is over?
  79. Is it possible to store arrays in a custom field?
  80. Get updated meta data after save_post hook
  81. Detect meta value changes when post is updated (post_updated)
  82. Multiple meta values for same meta_key adding on “Preview Changes” hit but not on saving or updating post
  83. Save HTML formatted data to post meta using add_post_meta()
  84. Custom Meta Boxes: Store two values in one repeatable field
  85. importing data from non-wordpress mysql db
  86. Populating meta box with select-list of existing posts, and assigning it to custom post types
  87. Transients vs CRON +Custom Fields: Caching Data Per Post
  88. How To Create a Metabox of HTML Content with Instructions For Editors When Editing a Post or Page?
  89. Unable to save datetime custom meta field using update_post_meta() function
  90. Up/Down voting system for WordPress
  91. post meta data clearing on autosave
  92. How to load php file for specific page in admin?
  93. How to set default metaboxes on user creation?
  94. Create custom field on post draft or publish?
  95. Display info from custom fields in all images’ HTML
  96. Metabox nonce PHP notice
  97. TinyMCE in Custom Metabox not loaded after upgrading from WP 3.1.4 to WP 3.2
  98. wp_editor in add_meta_boxes does not show gallery
  99. Ordering posts by anniversary using only day and month
  100. How do I assign this filter to a variable? (Appending php & markup to the_content)
Categories custom-field Tags custom-field, metabox, post-meta
How to make sure relative URL works when site is not on root domain?
When localizing a theme do I create the .mo and .po

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