I tried the code below on functions.php
function some_func($post_ID) {
global $authordata;
if( !is_null($authordata) ) {
wp_set_object_terms($post_ID,2,'item_cat'); // I want to get this result.
} else {
wp_set_object_terms($post_ID,7,'item_cat'); // $authordata seems to return NULL, and I get this result.
}
}
add_action('publish_my_post_type','some_func');
Eventually, I want to get a author ID(NOT current user ID for some reason) of editing page.
I think you are inside a template like single.php The $authordate is accessible inside the loop, so you may have forgotten to use