Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How can I output ONLY the post content (ie the text entered into the wysiwyg) and nothing else? i just need this for the posts in a specific category, so if i could call like say,

<?php get_template_part( 'venue_content', 'single' ); ?>

it would be ideal.

share|improve this question
    
you should mark chip's answer as accepted -- that way people will know you're not still looking for one when they scan the list of questions. –  marfarma Aug 28 '12 at 20:00
    
got it! thanks! –  jamie Sep 6 '12 at 17:19

3 Answers 3

up vote 1 down vote accepted

Assuming you are in the loop, or otherwise know (or know how to get) the $post object:

function wpse63358_get_post_content() {
    global $post;
    return $post->post_content;
}

If you want the formatted post content, replace this:

return $post->post_content;

...with this:

return apply_filters( 'the_content', $post->post_content );

To echo the function output:

echo wpse63358_get_post_content();

Edit

Note: if you just want to output post content in the template, you don't actually even have to bother with wrapping it in a function. Simply use:

global $post;
echo apply_filters( 'the_content', $post->post_content );
share|improve this answer
    
Or the single template for the OP's 'venue_content' could simply contain the line echo apply_filters( 'the_content', $post->post_content ); –  marfarma Aug 28 '12 at 17:03
    
marfarma: that worked! perfect thank you! –  jamie Aug 28 '12 at 17:08
    
@marfarma yes, of course; but I based my answer on the wording of the title: "how can i write a function that returns ONLY the post body". :) –  Chip Bennett Aug 28 '12 at 18:47
    
chip - I tried yours and couldn't figure out how to get it to work; not your fault, mine, for not being so familiar with altering default wordpress functionality. :) –  jamie Aug 28 '12 at 19:50
    
@jamie: you would define that function in functions.php, and then call it wherever you want the post content to output - i.e. wherever you currently have echo apply_filters( 'the_content', $post->post_content );. But that said, it would probably be more accurate to update the wording of the question/title. –  Chip Bennett Aug 28 '12 at 20:03

If you want to output only the post content, excluding any shortcodes, try something like this.

global $post;
$postContentStr = apply_filters('the_content', strip_shortcodes($post->post_content));
echo $postContentStr;
share|improve this answer

I think you can also use 'Post formats' for this, either the aside or the quote format I believe displays just the main content - http://codex.wordpress.org/Post_Formats

share|improve this answer
    
cool, that is new to me, i'll definitely check it out! –  jamie Sep 6 '12 at 17:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.