【发布时间】:2021-10-15 13:58:21
【问题描述】:
我需要在创建新帖子时将帖子状态从 pending 更改为 approved,如果作者之前有批准的帖子。
我有这样的功能,但代码根本不起作用。
请帮忙:
add_filter('wp_insert_post', 'change_post_status_when_insert_post_data',10,2);
function change_post_status_when_insert_post_data($data) {
if($data['post_type'] == "post") {
$posts_args = array(
'author__in' => $id,
'post_type' => 'post',
'post_status' => 'approved',
'posts_per_page' => -1,
);
$user_posts = get_posts($posts_args);
$count = count($user_posts);
if($count > 0) {
$data['post_status'] = 'approved';
} else {
$data['post_status'] = 'pending';
}
}
return $data;
}
【问题讨论】:
标签: php wordpress wordpress-theming hook