The following code block is giving me an accumulated result:

foreach($sections as $section) {
    $content_post = get_post($section->ID);
    $content = $content_post->post_content;
    $content = apply_filters('the_content', $content);
    echo $content;

If I catch the value of $content before the apply_filters(), it seems to work fine, but after and each result is appended to the previous value of $content.

If I change the final line to:

$content = wpautop($content);

It works as I want (I only need the paragraph formatting), but I am frustrated as I do not understand why the previous method hasn't worked.

  • 1
    Your initial code makes no sense to me. You are just overwriting $content repeatedly, without doing anything with it. Could you provide larger example of code in context?
    – Rarst
    Oct 10, 2011 at 13:41
  • I have pulled out the section that echo's the value of $content, as it is not relevant to the question.
    – Mild Fuzz
    Oct 10, 2011 at 15:28

1 Answer 1


I'm unable to replicate the problem you're describing. I'm guessing it has to do with one of two things:

An issue with $sections - how exactly is this populated?


A hook to 'the_content' somewhere else in your code - perhaps a filter function you wrote has a bug in it causing the duplicate content?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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