You can add another simple foreach loop to check if you have any values first:
foreach ( $meta_boxes as $metabox ) {
$has_value = false
foreach ( $metabox['fields'] as $field ) {
$meta = get_post_meta($post->ID, $field['id'], true);
if(!isset($meta[0])){
$need_title = true;
break;
}
}
if ($has_value){
echo $metabox['title'];
foreach ( $metabox['fields'] as $field ) {
$meta = get_post_meta($post->ID, $field['id'], true); //get post meta from each metabox
if(!isset($meta[0])) continue; //display only fields with values
echo $field['name'];
echo $meta ? $meta : $field['std']; //show value or default value
}
}
}
Related Posts:
- custom-meta-box checkboxes from loop won’t save
- Meta Box Plugin Cloned Fields – Multiple Foreach values
- get wordpress post loop by meta box date
- Metabox value for post loop?
- Get meta value when the page is a blog archive
- I want my post to republish again after adding a custom field
- Retrieve IDs from custom field, count and display results differently according to count
- Individual Widgets per Page
- How to add add_meta_box to specific Page Template?
- Adding another state (spam, reject, approve) to wordpress comments?
- Arrange custom fields with drag and drop?
- extend Meta Box / Document Panel
- Add multiple images to a page sidebar
- How to loop over custom fields in a page template?
- How to load php file for specific page in admin?
- How to set default metaboxes on user creation?
- Metabox nonce PHP notice
- TinyMCE in Custom Metabox not loaded after upgrading from WP 3.1.4 to WP 3.2
- Create custom field key upon theme activation
- How to save multiple metaboxes?
- add meta box using function.php
- Metabox image upload and custom field
- all tincymce’s switch when updating page after changing from html to text in custom metabox
- How to construct multiple meta boxes
- Force hide custom field metaboxes
- How do I exclude posts by custom field value?
- Create a random unique 6 digit number as custom field for custom post type
- Upcoming Event: How do I sort database by custom date field, but ignore past dates?
- Metabox will not save
- Odd PHP Code To Display HTML Of Meta Box [closed]
- custom field not saved
- Accessing loop functions (e.g the_title or the_content) from post ID
- How to create a Custom Meta Box with Name/Value Admin User Input Fields?
- Better Method for Multiple Meta Boxes
- Unsaved changes in metabox inputs not detected in the block editor
- Is there a better way to list all database terms alphabetically?
- Button inside Custom Meta Box triggering the Update Button
- How to show a post if was published less than two hours ago?
- Trying to retrieve post meta
- How can you include custom post meta in search without calling each key?
- Custom Fields – How to create a list from multi-line entries of a single value
- When creating a metabox do you have to create DB fields for the data?
- Saving zero in meta box
- how to make nsfw post with thumbanil
- Custom Query based on custom field of a single post
- Specific coditional usage [closed]
- Efficiently sort only certain categories by custom field
- Can I access a post meta field before the loop?
- Displaying page image in the footer automatically
- Set checkbox as checked by default in a metabox
- Why does this update_post_meta function not delete the custom field itself?
- Singleton Custom Field (Meta Box)
- Custom metabox not displaying multiselect data in edit mode
- How to validate select field in post meta?
- Show image if author meta (profile fields) exists outside loop
- Get post meta retrieving wrong value
- Can’t query by meta_key
- Is it preferable to use custom code to create metaboxes instead of plugins (such as ACF) and if so why? [closed]
- Get data from PHP to JavaScript to set position of each post on front page
- WordPress loop by meta key that is an array? and how loop multiple arrays
- How add multiple wp_editor_box to new post
- How to store multiple custom meta box
- ul list with only as many li’s as filled custom fields
- Displaying pages with a specific custom meta
- How to validation for sanitize_URL?
- put saved metabox values back into fields and then display on the front end
- HM CMB: Role Select
- Display background color or image with custom meta box?
- Collect Data from NEXT item while in loop
- Custom metabox not working
- Trying to implement AJAX into my admin pages. Am I improperly enqueue and localizing my scripts?
- How to Convert Custom Fields from Text to Array?
- Custom field outside the loop and inside an array
- WP E-Commerce Custom Meta > Serialized array
- Filter or order based on custom field
- Gutenberg add a custom metabox to default blocks
- HTML for adding a meta box (basic text field) to page editor?
- How to improve my non-unique metadata MySQL entries?
- Adding text box with add_meta_box
- How to avoid duplicate posts queried from custom meta?
- Add forms dynamically in admin pages?
- Where does php code to load data go?
- User Filter Options on Archive Page
- Sub Field of File Field
- How to make a shortcode for my WP_Query Loop? [duplicate]
- Counting number of images from loop
- If metabox fields has content display content
- Can’t save meta field value if the title not set
- Display Data From This Custom Media Upload Meta Box?
- Call the latest posts from a custom field group to be displayed on front-page
- If custom field doesn’t exist, or exists and it’s true show title?
- My meta boxes update wp_postmeta of posts but not of pages. What is wrong with the code?
- Where can I find the code for the menu page meta boxes?
- Custom Meta Box If Else Statement
- Display posts where date field matches current month?
- PHP Puzzle: Unique Styles with PHP loop
- Pagination not displaying correct number of pages
- How do I filter a custom post type loop by a field?
- Custom field not showing
- I want to show image from custom field image on my custom page template