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
- 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?
- Create Multiple File Upload Metabox in WordPress
- Users Select inside custom metabox
- Custom Metabox Not Saving
- Better Method for Multiple Meta Boxes
- how to fetch the meta field keys/meta boxes from a post type?
- Loop with slider (slider not loading)
- How to Create Dynamic Fields in a Meta Box?
- Set front page option using custom fields?
- Should custom meta boxes be able to output shortcodes the same as WordPress’ native post editor?
- Can’t get metabox value (a url) returned using WPAlchemy
- Unsaved changes in metabox inputs not detected in the block editor
- Limit the number of acf content when displaying in post loop [closed]
- Need Help Fixing My Iframes [closed]
- Custom Meta Box (SELECT) Not Saving
- How can I add extra word in permalink when someone click download button?
- Get updated meta value after post update or published (custom post type) using hook
- Is there a better way to list all database terms alphabetically?
- Button inside Custom Meta Box triggering the Update Button
- Why is my Custom Meta Box Field Inputs NOT saving?
- Change the main loop WordPress impact on the server?
- How to show a post if was published less than two hours ago?
- List users by sum of all their posts’ custom field values
- Trying to retrieve post meta
- Custom Metabox additional item
- get_posts in meta box dropdown not showing latest posts
- I need a “Choose from existing content” popin
- Outputing a metabox textarea and avoid line breaks inside li tags
- How can you include custom post meta in search without calling each key?
- Display Custom Meta Box Field Only If Value is Present
- Add additional field to custom post_type
- 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?
- shortcode in a custom metabox
- 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
- Find a way to retrive data updated through metabox plugin to web page
- 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)
- Problem with saving large amount of data in postmeta/usermeta
- Custom metabox not displaying multiselect data in edit mode
- Move Title and the Content WYSIWYG editor position
- How to validate select field in post meta?
- Show image if author meta (profile fields) exists outside loop
- Get post meta retrieving wrong value
- How can I hide custom field from users used for caching response from external api?
- Can’t query by meta_key
- How to use media upload on metabox post page without breaking TinyMCE?
- Displaying Meta-Box Data Properly
- Let’s Create Custom Field Template Documentation
- Show ACF field with link to ultimate member profile/WordPress user profile below the post (single post layout)
- Is it preferable to use custom code to create metaboxes instead of plugins (such as ACF) and if so why? [closed]
- Values entered in a meta box aren’t saved
- 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
- Scripts and tags will not save or output from my custom meta box
- How to store multiple custom meta box
- ul list with only as many li’s as filled custom fields
- Using WP Color Picker in Repeatable Fields
- MetaBox not saving after empty
- Displaying pages with a specific custom meta
- Can I save post meta programatically without setting metaboxes?
- Loop through incrementing custom fields
- How do I save Multiple fields in a meta box?
- Enable a short code in the custom meta field
- do_shortcode close
- Search Results Page – Displaying Custom Meta Fields
- How to validation for sanitize_URL?
- Meta box values are displayed on Custom Fields list. Is it possible to hide them?
- If metabox has content display content
- put saved metabox values back into fields and then display on the front end
- Custom meta boxes not saving
- HM CMB: Role Select
- If custom field doesn’t exist, or exists and it’s true show title?
- wp_postmeta are updated for only one page
- My meta boxes update wp_postmeta of posts but not of pages. What is wrong with the code?
- Order by custom field attribute
- How can I put a custom field as the link of a button shortcode?
- Meta Box Data added to header redirect
- Can i categorise my meta box?
- Show message if statement is false – foreach
- Where can I find the code for the menu page meta boxes?
- How can I create a menu items from meta box based on users input
- Custom metaboxes not saving after switching themes