Skip to content

Instantly share code, notes, and snippets.

Last active May 9, 2022 16:37
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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.
* 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;
Copy link

joshespi commented May 9, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment