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.

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.

share|improve this question
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 '11 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 '11 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?

or

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?

share|improve this answer

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.