Something like this:
$ck = get_post_custom_keys($post_id); //Array
// drop keys starting with '_'
$ck = array_filter($ck, function($key){
return strpos($key, '_') !== 0;
});
// store your root keys here
$data = array();
foreach($ck as $k){
$cv = get_post_custom_values($k, $post_id ); //Array
// drop empty values
$cv = array_filter($cv);
if($cv)
$data[$k] = $cv;
}
if($data){
// your html here; iterate over $data
$html="";
foreach($data as $key => $contents)
$html .= sprintf('<h4>%s</h4><div class="customfield-content"><p>%s</p></div>',
esc_attr($key),
implode('</p><p>', array_map('esc_attr', $contents)));
printf('<div class="customfield-box">%s</div>', $html);
}else{
// nothing
}
Related Posts:
- ORDER BY custom field value
- Best way to programmatically remove a category/term from a post
- Custom user avatar in the WordPress users listing
- query_posts and only show results if a custom field is not empty
- User Profile / Add Custom Fields
- Convert jQuery Datepicker Format to SQL Date Format
- Only show metabox when date-value in other metabox is over?
- Is it possible to store arrays in a custom field?
- Assign/update the custom field value for all posts
- HTML / Javascript in custom field textarea?
- Display newest post’s custom field content on homepage, daily
- Saving an array in a single custom field
- Order posts according to user defined order for meta values?
- Calculate the sum of certain the_sub_fields
- Is it possible to order posts by two meta values?
- Loading scripts to the Post Edit page only
- Registration and Profile custom field
- Per site configuration
- Alternative to simple fields plugin?
- Calling custom fields for pages (not posts)
- Add More Fields to Users Pages (Admin Panel)
- how can i use custom field in query post
- wp_editor not saving data, and text area showing html tags
- Get specific custom field keys from a post and put into an array
- Dynamically fill a post custom field with post publish date
- Create new post with meta data using WordPress API
- Select multiple options in WordPress custom meta filed
- get_terms that have custom sticky field checked
- Users Select inside custom metabox
- filtering custom post types via meta data drop down
- Get content from pages with same meta_key from Database
- Speed up / Optimize Admin Edit Post Page on Large Websites (50-150k posts, 50 custom fields per post)
- Add & store extra fields – WordPress Comments
- Why is my Custom Meta Box Field Inputs NOT saving?
- Filter multiple custom fields Values with Check boxes
- Get registered custom fields or post meta even if empty
- Pass current post title to a predefined link
- Restrict WordPress Search to Custom Field
- How to mass update custom fields for more than 20k posts
- remove initial wysiwyg editor from cms page edit
- shortcode in a custom metabox
- List all unique custom field values?
- Build index page from custom fields
- Importing WordPress Posts With Custom Meta Data As CSV Files Through PHPMyAdmin
- How can php be used to return data from custom fields in a post?
- Modify date query by URL parameter using pre_get_posts and $_GET
- Upload & include specific JavaScript files for posts?
- help for user login
- The best way to collision check in WP
- Get meta field value of all catgories
- Displaying a custom field containing a list creates unwanted markup
- Output custom field as ul list
- How to store meta field values
- Multiple Custom Field Query
- Group Posts By Custom Meta Value: Date
- Change Page Order by Custom Field (Magic Fields)
- Custom Field is getting the value of another page/post instead of the current one?
- Custom Field Date Problem
- Approach to creating a site with this structure
- How can I detect user’s timezone?
- ACF field group not showing in page
- Filter post style attribute
- Update some (not all) post titles with custom field values before running the Loop
- how to turn a link field into a button or link text
- Arrays in custom fields or is there a better way?
- Use value from ACF to populate other fields
- Dynamically populate query source in Elementor post widget
- Custom field in media library not saving, selected() function not adding “selected” to select list input type
- Setting user permissions per post
- Adding Facebook’s image and meta description retrieval capabilities to a WordPress post
- Weird custom fields data lost
- Why does my numeric meta query work only on one meta key and not the other?
- Showing the post only when there is title, thumbnail and the content in Custom Fields
- WooCommerce 3 get custom variation on process order [closed]
- query_posts -> get page_id from custom field
- author global display format
- Custom field group on page
- Output Custom Field value to shortcode
- Update custom table on metabox POST
- display custom media folders to wordpress media popup
- Should I store arrays in custom fields or create custom tables?
- Problem saving meta data
- Term specific featured post on taxonomy archive pages
- change attachment custom field onChange event
- Custom Meta Boxes and Fields for WordPress: Change directory upload based on user-edit page
- WP_query returns error when used for custom widget
- Get custom field from other post in carousel
- Form fields based on custom fields
- show custom field content in jquery tabs
- Create citation and url in post using 3 custom fields with conditions for each field… So close!
- Post rating using Custom Field
- Inserting custom fields into new-post.php without using the Custom Fields Template plugin?
- woocommerce how in checkout to add my custom field check box, and when i check it hide the shipping adress and add tax 19% [closed]
- How can I attach files without using a plugin?
- Advanced Custom Fields for Header that are Editable from a Page [closed]
- Show only first image of multiple image field
- Change Fields of Comments and make them searchable?
- Shortcode not picking up custom field
- Custom Fields after update to WordPress 6
- Conditional display based on ACF checkbox