7

in my wordpress site, the_content() is not showing the content, but $post->post_content shows it, why this is happening? and how can I use the_content again?

  • 2
    What is the code that surrounds that? Are you in the loop? – mor7ifer Mar 2 '12 at 2:58
  • What Theme are you using? If it is a custom Theme, then we will need to see the custom code for the template file in question. – Chip Bennett Mar 2 '12 at 3:24
  • I got on one of those problem. I believe it occurs due to a another WP_Query made before the_content(). – ifdion Mar 2 '12 at 11:10
  • Happened to me when upgrading to WP5 – Fanky Jun 28 '19 at 11:59
9

In order to use "the_content()" it must be used within The Loop.

See here: http://codex.wordpress.org/Function_Reference/the_content

"Displays the contents of the current post. This tag must be within The_Loop."

  • its a single.php and it worked before – srisar Mar 2 '12 at 3:03
  • 4
    but then how $post->post_content works? plus, the_title() also works.. – srisar Mar 2 '12 at 3:04
  • Even single.php needs to have The Loop on it to retrieve the content and custom meta field values. As for the_title() [if I'm not mistaken] is an always defined field. You can't have a published post without a title being input. To be technically and WP correct, the_title() should be within The Loop as well. If you're against using The Loop and $post->post_content works, you could always use the apply_filters() function to display the content. codex.wordpress.org/Function_Reference/… – The Z Man Mar 2 '12 at 3:09
  • thanks, for your reply, I just wondered why it stopped working, it did worked before. anyway thanks, if I found my fault I will surely post here so it might help someone. – srisar Mar 2 '12 at 3:14
  • No problemo srisar! Best of luck going forward. If you find a better solution or answer, yes, please post it back here :) – The Z Man Mar 2 '12 at 3:18
3

If it worked before, it's probably a plugin hooking into the_content filter. Disable your plugins one by one to see if this fixes the issue. Next, check the callback functions for the_content filter.

You can see every callback for the_content by adding the following:

add_action('template_redirect', 'wpse_44152_template_redirect');
function wpse_44152_template_redirect(){
    global $wp_filter;
    print_r($wp_filter['the_content']);
}

Find each of the functions listed by doing a 'find in files' code search on your code editor. A filter callback HAS TO return $content data back for the_content() to work properly.

1

you can check your functions.php in your theme folder,find if some function do something for the "the_content" function.my theme have the same problem,and I found a function has a mistake and cause "the_content" can't work

find text like "the_content" in your functions.php,

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