Skip to content

Instantly share code, notes, and snippets.

@chrismademe
Created July 25, 2019 15:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismademe/5df7f0a55a178f43d4983df31140e025 to your computer and use it in GitHub Desktop.
Save chrismademe/5df7f0a55a178f43d4983df31140e025 to your computer and use it in GitHub Desktop.
get-post-with-fields.php
/**
* Get Post with Fields
*
* Returns a post with it's ACF fields
* attached to it
*
* @NOTE We don't use $post as a variable
* inside here so we don't mess with the
* WordPress global variable
*
* @param int $id Post ID
*/
function get_post_with_fields( $id ) {
// Get Post
if ( !$the_post = get_post($id) )
return false;
// Add the fields
$the_post->fields = get_fields($id);
// Done!
return $the_post;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment