Post Pic

WordPress hack: Easily get post content by ID

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

Sep 20 2012 11:27

I was searching through wordpress codex for this info…glad I found your website….very helpful.

Thanks for the share.

Jude C

Oct 02 2012 19:08

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

Oct 03 2012 09:08

@Jose: I explained it here: http://www.wprecipes.com/how-to-find-wordpress-category-id

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required

WP Theme of the week

Sponsored Likebox