Created
July 25, 2019 15:25
-
-
Save chrismademe/5df7f0a55a178f43d4983df31140e025 to your computer and use it in GitHub Desktop.
get-post-with-fields.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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