0
親の作者で保存されたハーモノグラムの作者を変更しようとしていますが、機能に対するものは機能していないようです。私が定数値を持つ著者IDを設定すると、すべてが機能します。ここで保存された投稿の作成者を親投稿者として設定
$parent_post_id = wp_get_post_parent_id($post_id);
$post_author_id = get_post_field('post_author', $post_id);
は全体の機能である
function func_auto_update_post_author($post_id) {
$post_type = get_post_type($post_id);
if ("harmonogram" != $post_type) return;
//$parent_post_id = get_queried_object_id();
$parent_post_id = wp_get_post_parent_id($post_id);
$post_author_id = get_post_field('post_author', $parent_post_id);
$my_post = array(
'ID' => $post_id,
'post_author' => $post_author_id,
);
remove_action('save_post', 'func_auto_update_post_author');
wp_update_post($my_post);
add_action('save_post', 'func_auto_update_post_author');
}
add_action('save_post', 'func_auto_update_post_author');
_ "空だと思う" _ - "考えない" - _verify_。 'var_dump'を使って変数に実際に何が含まれているのかを確認してください。 – CBroe