Change post categories while saving post
I'm trying to change post categories inside a save_post action callback function, but I get endless recursion, because wp_u开发者_开发知识库pdate_post method fires save_post action itself.
Maybe somebody did this before& Or there is a way to change post categories without using wp_update_post method?
you can pass the new categories to the function, in the same way you add the post.
$newcats = array(
get_cat_id($catname_one),
get_cat_id($catname_two),
get_cat_id($catname_three),
get_cat_id($catname_four)
);
$wpx_post_arr = array(
'ID'=>$post->ID,
'post_category'=>$newcats
);
wp_update_post($wpx_post_arr);
I think this is a correct answer for wordpress 3.1 + : https://wordpress.stackexchange.com/a/72351/44018
in this case the loop is not coming ;-)
精彩评论