Last active
May 9, 2022 16:37
-
-
Save wpscholar/4553288 to your computer and use it in GitHub Desktop.
An example of how to fetch post meta using the new WP_Post object.
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
<?php | |
/** | |
* Pre WordPress 3.5, this is how we had to fetch post meta | |
*/ | |
$post = get_post(); | |
$last_name = get_post_meta( $post->ID, '_last_name', true ); | |
/** | |
* As of WordPress 3.5, the new WP_Post object allows us to fetch post meta this way | |
*/ | |
$post = get_post(); | |
$last_name = $post->_last_name; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this was exactly what i needed thank you.
I was trying to get this in a plugin function and it kept returning a bool instead of a string. I assume now it's because the proper post ID wasn't getting used.