[wp-hackers] Setting custom taxonomy on the fly
Otto
otto at ottodestruct.com
Sun Apr 17 17:41:02 UTC 2011
On Sun, Apr 17, 2011 at 11:49 AM, Dougal Campbell <dougal at gunters.org> wrote:
> So that leaves us with just a couple of other opportunities to act: the
> 'wp_insert_post_data' filter, and the 'wp_insert_post' action. With the
> filter, I can detect my sentinel string and strip it back out of the post,
> but I can't set the post_format, because we don't have a post_ID yet. But if
> we get all the way to the 'wp_insert_post' action, updating the post content
> to strip out the sentinel is a problem, because using wp_update_post() will
> in turn call wp_insert_post(), which is a recursive loop.
Why not just use both?
add_filter('wp_insert_post_data','strip_content');
function strip_content($data) {
global $my_format;
// detect format in $data['post_content'] and modify it
// set $my_format = detected-format;
return $data;
}
add_action('wp_insert_post','add_format');
function add_format($post_ID) {
global $my_format;
set_post_format($post_ID, $my_format);
}
-Otto
More information about the wp-hackers
mailing list