我正在尝试向我的 Wordpress 网站添加一项功能,即每次添加帖子(自定义帖子类型)时,都会创建另一个帖子(不同的自定义帖子类型)。
我尝试在我的函数文件中添加一个动作,但它似乎不起作用。
函数.php
function add_notification($post_id) {
global $wpdb;
$post_type = get_post_type($post_id);
if($post_type == 'exercises'){
$title = "BLA";
$post_id_new = wp_insert_post(
array(
'comment_status' => 'closed',
'ping_status' => 'closed',
'post_title' => $title,
'post_status' => 'publish',
'post_type' => 'notification'
)
);
}
}
add_action('publish_post', 'add_notification');
我也尝试过使用其他钩子,如 new_to_publish 和 publish_post
有了这个,当我添加一个练习帖子时,我期待有一个新帖子(通知)。
我认为这是我忘记的愚蠢的事情,但我已经陷入了这个问题已经有 3 天了。
饮歌长啸