You can try this to fetch the custom values:
$c1 = get_post_meta( get_the_ID(), 'custom1', TRUE );
$c2 = get_post_meta( get_the_ID(), 'custom2', TRUE );
$c3 = get_post_meta( get_the_ID(), 'custom3', TRUE );
$c4 = get_post_meta( get_the_ID(), 'custom4', TRUE );
Then to calculate the average:
// check if c1, c2, c3 and c4 are all set:
if( strlen($c1) * strlen($c2) * strlen($c3) * strlen($c4) > 0 ){
// convert the values from string to int/float:
$c1 = 1 * $c1;
$c2 = 1 * $c2;
$c3 = 1 * $c3;
$c4 = 1 * $c4;
// calculate the average:
$avg = ($c1 + $c2 + $c3 + $c4) / 4 ;
// output:
// var_dump($avg);
printf( "The average is %.2f", $avg ); // with two decimals:
}else{
echo " missing value! ";
}
Related Posts:
- Meta Query with AND & OR?
- Problem with serialized arrays in custom meta
- explode array within shortcode
- Can I count the number of users matching a value in a multiple value key?
- WP doesn’t show Array Custom Fields?
- How do I search an array stored in a custom-field using WP_Query?
- Custom text-only header
- How to delete custom field “suggestions” from dropdown list
- How to save custom fields for attachments
- How to get a meta value from all post
- Adding existing user custom field value to a woocommerce product [closed]
- How to save values of a custom input field on the Network > Site Info screen
- How to load php file for specific page in admin?
- How to set default metaboxes on user creation?
- Exclude custom post type from search by custom field value?
- ajax jquery update custom field meta value front end
- Add input field to ‘Pages > Edit Page’ through functions.php
- Adding Custom Text Area to WooCommerce Product
- get_post_meta not working inside loop
- Get multiple custom field values in a $wpdb query [duplicate]
- add meta box using function.php
- How do I exclude posts by custom field value?
- Upcoming Event: How do I sort database by custom date field, but ignore past dates?
- Auto populate a meta box field from another meta box field when publish or save
- Buddypress Add unserialized Profile Fields in Members Loop [closed]
- Add Paypal Button programmatically
- How do I use wp_query for WordPress search?
- Nav Menu – Add class based on meta keys
- Eliminating the appearance of a specific custom field in a post
- Conditional custom field query
- Display two custom values from a post
- Find page IDs with specific meta tag key value pairs
- Order query by meta_value with multiple custom fields
- Conditionally hide or show woocommerce product variation in fontend by custom field
- custom meta box text field: how to limit to alpha or numeric only
- Accessing loop functions (e.g the_title or the_content) from post ID
- Create an Array of Specific Custom Post Meta
- custom avatar removal
- Excluding Specific Fields from Profile Builder Registration Form
- Send email with custom fields after new draft is saved or new post published
- How to add upload video option in wordpress for user?
- Get posts with same meta value as current post
- Add custom field to all posts in specific post_type
- Set post to unpublished after one week depending on condition
- query posts custom field calculation value
- Get Data From wp_sitemeta for Multisite network
- Efficiently sort only certain categories by custom field
- How can I do a variable for meta_query?
- Syntax Issue: How Do I Call A Custom Field Inside a ForEach Statement? [closed]
- How to list Category list in ACF Pro’s Select Field to choose from [closed]
- Singleton Custom Field (Meta Box)
- Display custom field & value correctly on page
- Displaying custom filed content instead of post content
- Save all the post tags inside a custom field
- How to add fields in custom registration form, validate it and aave to db? [closed]
- How to update a custom field in all posts with the value of another custom field in the same post?
- Set featured image from custom field URL
- Best Way to get facebook share count and update using wp_schedule_event or any other method
- Get YouTube video id from url in a custom field
- Filter posts by custom field (Advanced Custom Fields)
- How to insert multiple checkbox values into post as custom fields from frontend
- Custom metabox not working
- How to get custom image field of specific post id
- Custom field to array?
- wp_get_attachment_image_src() with advanced custom fields returning empty
- How to update custom field of a posts in a particular category
- How to query posts by month based on date custom field?
- Change word in woocommerce product category custom field
- get posts based on non-single metadata
- Problem with revisions only returning four results
- Woocommerce products search with custom fields
- Convert author metadata to a custom field
- Add forms dynamically in admin pages?
- Custom pages or Custom Posts
- get_avatar filter is not working as per requirement
- Saving Custom Field that includes Quotation marks
- WordPress Admin – Automatically Sort Custom Posts by Custom Field Date Value in d-m-Y Fomat
- how can i show WordPress custom field data to my short code?
- how to execute custom field for structured data?
- Saving custom form data
- searching by keywords in post’s metas or pagination links problem
- Permanently show Custom Fields in Editor
- select user with all meta field and field value. I am use Below Query for this ,So any of know another way to fast query instead of below query?
- Retrieve Google API JSON data and store as WordPress Custom Fields
- meta_query ‘compare’ => ‘!=’ not working
- Echo out custom fields in comments
- Why WordPress takes time to make request to save post?
- Show comon custom field results?
- Display Data From This Custom Media Upload Meta Box?
- Display Child Page with custom fields within Parent Page
- Convert all dates in field to Unix time, except those already in Unix time
- Load code for custom fields only on admin pages?
- Pagination not displaying correct number of pages
- Show div based on custom meta value
- Assign class to Drop Down Selections in WooCommerce Products Custom Fields
- Show/Hide Featured Image or replace it with custom field [closed]
- Add CSS class to posts with certain meta key
- Match submitted array fields with the MYSQL database fields to update them correctly in PHP
- Best way for managing images of ads banners
- Crop custom image size vs actual size