我想在WordPress一个删除一个自定义类型后后与特定的标题和当前用户为作者添加一个按钮。这发生WordPress的 - 删除自定义类型后后
问题是,所有的帖子被删除,所有job_alert岗位,不仅为这个特定作者或与此称号。
有人可以看到为什么吗?
$delete_post = array(
'post_type' => 'job_alert',
'post_title' => $title,
'post_status' => 'publish',
'post_author' => $current_user->ID
);
$posts = new WP_Query($delete_post);
if ($posts->have_posts()) {
while ($posts->have_posts()) {
$posts->the_post();
wp_delete_post(get_the_ID());
}
}
我也有这个代码,创建一个职位,这很好。类似的代码。
$new_post = array(
'post_type' => 'job_alert',
'post_title' => $title,
'post_status' => 'publish',
'post_author' => $current_user->ID
);
$post_id = wp_insert_post($new_post);
您的查询是否按预期工作?使用循环内的'var_dump(get_the_ID())'来查看响应包含的帖子数量。 –