这应该是可能的,但需要一些工作。正如你所发现的,在wp_insert_post
功能,有一个挂钩save_post_{$post->post_type}
, 创建具有特定自定义帖子类型的帖子时,可以对其他内容执行此操作。但是,如果使用此钩子创建其他帖子,将再次遇到该钩子,最终将进入无限循环。因此,您必须确保挂钩不会再次使用。它是这样的:
add_action (\'save_post_yourcustompostname\', \'wpse359582_make_three_posts\');
function wpse359582_make_three_posts ($post_ID, $post, $update) {
// remove the hook so it won\'t be called with upcoming calls to wp_insert_post
remove_action (\'save_post_yourcustompostname\', \'wpse359582_make_three_posts\');
// make three copies
$post1 = $post;
$post2 = $post;
$post3 = $post;
// Now manipulate the three posts so each has a unique IMEI number
....
// update the original post
wp_update_post ($post1);
// remove the id from the other two posts so WP will create new ones
$post2[\'ID\'] = 0;
$post3[\'ID\'] = 0;
wp_insert_post ($post2);
wp_insert_post ($post3);
// put the hook back in place
add_action (\'save_post_yourcustompostname\', \'wpse359582_make_three_posts\');
}