Question

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?

Was it helpful?

Solution

the_content filter takes only one parameter - $content, so you can't check what post this $content comes from.

So if the plugin Team performs incorrect checks (it can for example use is_singular( <POST_TYPE> )), then it will modify all contents printed on single team member page.

You'll have to check what functions are assigned to the_content hook and check what exactly are they doing...

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top