1 回答

TA贡献1951条经验 获得超3个赞
对于自定义帖子类型,我们必须使用像 add_action('publish_custom-post-name','function'); 这样的钩子。在您的情况下,您必须使用如下所示
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_exercises', 'add_notification');
请试试这个。如果有任何疑问,请随时询问。
- 1 回答
- 0 关注
- 131 浏览
添加回答
举报