What I want: the array of posts returned by creating $query = new WP_Query($args);
Why: to return specific content as a sort of API request in json format, ready to display on another site
What I tried first:
foreach($query->posts as $post) {
$post->post_content = apply_filters('the_content', $post->post_content);
};
This performed the autop
and do_shortcode
filters correctly, but no the oembed
transformation.
What I ended up doing:
while($query->have_posts()) : $query->the_post();
$query->posts[$query->current_post]->post_content = apply_filters('the_content', get_the_content());
endwhile;
The only difference in output, is that inside the loop it performs the oembed, outside it does not. Where does this difference come from, and is there a better way I should have done this?
I checked global $wp_filters
and oembed
is definitely listed under [8]
, so it wasn't a filter loading issue.