,

Include plugin content in your get_the_content call

First, let’s define when you’d use this. Here’s where I as at.

I was pulling in a most recent post into a page that was not the blog. Not just onto a page, but into a custom post type (for displaying small content on the home page) that only had a couple of fields available to me for use. These posts have PodPress podcasts attached to them, and I needed that information. I needed to make it simple for the user, so I wanted to make a shortcode to pull the most recent post.

If you’re in the loop and you call the_content() you get everything you’d expect to. When you’re making a shortcode and need to return all of your data instead of just echo or print it, you need to use get_the_content(). Normally this isn’t a problem, but if you’ve got plugins or other things filtering their data in using add_filter(‘the_content’), then that data won’t be pulled in.

Looking back, I can see that the following important step is included in the bottom of the codex’s get_the_content page, but here is the magic code to get your plugin data included:

apply_filters( 'the_content', get_the_content() );

so my use looked something like this:

$output .= apply_filters( 'the_content', get_the_content() );
return $output;

with that, all of my fancy PodPress functionality was included.

Comments

3 responses to “Include plugin content in your get_the_content call”

  1. Thanks man! Just what I nedded.

    1. You’re welcome!

  2. very useful … had issues with WP Quad , now used it and relieved.