Difference between the_content() and get_post()?

post_content is a property of the WP_Post object. WP_Post is an object representing the post data from the database. So post_content contains the raw content as stored in the database.

the_content() is a template tag that displays the content of the current post. The ‘current post’ is whatever the global $post variable is set to at the time the function is run. The global $post variable is normally set within The Loop with while( have_posts() ) : the_post();.

The crucial difference is that the_content() runs the raw content through several filters that prepare it for display. These do things like adding paragraph tags, converting URLs to embeds for things like videos, and converting symbols like quotes to smart quotes etc. Many plugins use this filter as well, for adding things like Share buttons.

So if you just echo the post_content it probably won’t look right. You can mimic the output of the_content() on raw data by applying the the_content filter manually. So in your example you would do:

$post = get_post();

$split_content = explode( '|', $post->post_content );

echo '<h4>' . $split_content[0] . '</h4>';              
echo apply_filters( 'the_content', $split_content[1] );

Leave a Comment