1

I created a plugin that adds content from another post, and places this content next to the original content. I can say, that this content should appear at the bottom of the original post content.

I get post_content for my additional post, and then call apply_filter('the_content', $custom) but this code does this not only for my $custom, but for original content as well! What am I doing wrong?

add_filter( 'the_content', 'custom_content' );

function custom_content( $content ) {

    $customPost = get_post( 22 );
    remove_filter( 'the_content', 'custom_content' );
    $html = $customPost->post_content;
    $html = apply_filters( 'the_content', $html );

    return $content . $html;

}
  • When you say "this code does this" can you describe in more detail what happens and what you would prefer to happen? – Andy Macaulay-Brook May 26 '16 at 7:25
  • Yep :) I want to get filtered content of post, wit applied filters,hooks, etc like in normal mode - and place it after content exactly. It should look that I open Post #1, I see render result, and at the end of this post I want include Post #2 content. It works with simple blog posts, but with page builder (for example Avia) it brokes, and put extra tags.. – d7p4x May 26 '16 at 10:54
  • Looks like I should reset everything or something like this, and then render it again..huh – d7p4x May 26 '16 at 10:55
  • Ah if you're content is being messed about by a third party page builder then I wouldn't know, sorry. – Andy Macaulay-Brook May 26 '16 at 10:57
0

the_content will return the whole content of the post and not particular part. If you want to access your particular part, then you can go for shortcode.

For eg, if you have content like this in your post

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's [mycustomtextpart] standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has

Then use do_shortcode function to make changes in the [mycustomtextpart] section. Refer.

  • Yep. But...I use page builder Avia framework for requested custom page that should be placed after content. But..when I apply filter the_content it brokes main content, and return it to shortcoded version.. – d7p4x May 26 '16 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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