[wp-hackers] How To Get Completely Processed Body Of Blog Posts?

Otto otto at ottodestruct.com
Thu Aug 19 18:01:53 UTC 2010


You can skip the setup_postdata(), the global, the reset...

$mypost = get_post(whatever);
$content = apply_filters('the_content', $mypost->post_content);

Note: Badly made plugins that use shortcodes for inappropriate things
will complain at you about doing this. I've seen cases where
processing the_content filter will a) Add items to a cart in a
shopping plugin, b) make a site do heavy processing because it's doing
too much database work for the shortcode, c) make duplicate posts on
twitter/facebook/other...

Basically, many plugin authors don't know that shortcodes shouldn't do
heavy lifting or that they can be called more than once on a page,
etc. So expect issues whenever you use the_content filter in this way.
However, that's their problem, not yours.

-Otto



On Thu, Aug 19, 2010 at 10:19 AM, scribu <scribu at gmail.com> wrote:
> On Thu, Aug 19, 2010 at 6:12 PM, Raj <list at expost.org> wrote:
>
>> I have a plugin that uses the body of blog posts to deliver e-mails. Often
>> times the plugin users would use shortcodes [caption][/caption] etc.  I am
>> sure there are many plugins which define some shot codes too. How do I get
>> the body of a post after all the shortcode replacements and other
>> processing
>> by other plugins have been performed?
>>
>
> global $post;
> $post = get_post( 'some id' );
> setup_postdata($post);
>
> $processed = apply_filters('the_content', $post->post_content);
>
> wp_reset_postdata();
>
>
> --
> http://scribu.net
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list