When building a custom theme, you often need to get the content or title from a specific post. Sometimes, using a custom loop is the better option, but when you only to get information from a specific post, there’s a better option – just read on!
When building a custom theme, you often need to get the content or title from a specific post. Sometimes, using a custom loop is the better option, but when you only to get information from a specific post, there’s a better option – just read on!
Simply use the get_post_field() function to get the post content. The following example will display the content of the post with id $post_id:
echo get_post_field('post_content', $post_id);
Indeed, the function can be used to get other fields from the post. See the codex page for reference.
3 Responses
I was searching through wordpress codex for this info…glad I found your website….very helpful.
Thanks for the share.
Jude C
Thanks for the tip but extending a little bit how you can get the ID of specific category from any post??
Actually when I go to administration and just hover the mouse in the specific category I just get a slug or name of the category.
I will appreciate if you know how to do get the ID.
Cheers,
Jose V
@Jose: I explained it here: http://www.wprecipes.com/how-to-find-wordpress-category-id
Trackbacks: