Using apply_filters(‘the_content’, $custom_query->post_content) alters output

Disclaimer: sorry if this has been asked/answered, but I couldn’t find the right search phrase to get something similar.

I’m editing a template for a site I did not build, and I stumbled across funky behaviour. It’s probably intentional and not a bug, but can someone explain why this happens?

This site uses a plugin called Teams that allows the client to input their staff members. It appears to use single.php to output the team members (which in turn seems to load content-single.php via get_template_part( ‘content’, ‘single’ );.

In the footer of the site, a disclaimer was hardcoded like this:

$disclaimer_post_id = 311;
$disclaimer_query = get_post($disclaimer_post_id);
$disclaimer = apply_filters(‘the_content’, $disclaimer_query->post_content);
echo $disclaimer;

So! On each “regular” page on the site, this works just fine. However, when viewing a single team member, it actually re-outputs their fields (name/title, writeup/description, even social media links and edit button like a normal WP post) so instead of a disclaimer we get duplicated content in the footer from above.

I went through and did a print_r() on $disclaimer_query and I can see that $disclaimer_query->post_content is actually the disclaimer text!

Here’s my question:

Why does apply_filters() alter the output? Does it have something to do with the fact that no custom query seems to be used before get_post() is called?

Read more here:: post_content) alters output” rel=nofollow>Using apply_filters(‘the_content’, $custom_query->post_content) alters output

Leave a Reply

Your email address will not be published. Required fields are marked *