Skip to content

Instantly share code, notes, and snippets.

@tdrayson
Last active December 23, 2020 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tdrayson/5014cfe452cc1a9be21e8cd6100ad943 to your computer and use it in GitHub Desktop.
Save tdrayson/5014cfe452cc1a9be21e8cd6100ad943 to your computer and use it in GitHub Desktop.
//Get the Custom Post Type
// -1 means we get all the posts type.
<?php
$things = get_posts(['post_type' => 'CPT','posts_per_page' => -1]);
//Start with 0 calories
$total = 0;
//Then Loop through all the posts in your CPT
Foreach($LotsofPosts as $singlePost):
//well grab the calories from each post
$post_data = get_field('field_name',$singlePost->ID);
$total = $total + $post_data
endforeach;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment