1 回答

TA貢獻(xiàn)1951條經(jīng)驗(yàn) 獲得超3個(gè)贊
對于自定義帖子類型,我們必須使用像 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');
請?jiān)囋囘@個(gè)。如果有任何疑問,請隨時(shí)詢問。
- 1 回答
- 0 關(guān)注
- 155 瀏覽
添加回答
舉報(bào)