Change message categories when saving a message

I am trying to change the post categories inside the save_post action callback, but I get infinite recursion because the wp_update_post method fires the save_post action.

Maybe someone did this before & Or is there a way to change the post categories without using the wp_update_post method?

+2


a source to share


2 answers


you can pass new categories to the function, just like you add a 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);

      

+1


a source


I think this is the correct answer for wordpress 3.1+: https://wordpress.stackexchange.com/a/72351/44018



in this case, the cycle does not occur; -)

0


a source







All Articles