是否可以使用SQL或函数代码发布所有的草稿帖子?我尝试在我的函数文件中使用此代码,但不起作用。
add_action('admin_init','wpse_244394');
function wpse_244394(){
$args = array('post_type'=> 'post',
'post_status' => 'draft',
'posts_per_page'=>-1
);
$draft_posts = get_posts($args);
foreach($draft_posts as $post_to_publish){
$query = array(
'ID' => $post_to_publish->ID,
'post_status' => 'publish',
);
wp_update_post( $query, true );
}
}
发布于 2018-04-08 15:24:50
尝试使用"wp_publish_post( $post_id )“而不是"wp_update_post”。
add_action('admin_init','wpse_244394');
function wpse_244394(){
$args = array('post_type'=> 'post',
'post_status' => 'draft',
'posts_per_page'=>-1
);
$draft_posts = get_posts($args);
foreach($draft_posts as $post_to_publish){
wp_publish_post( $post_to_publish->ID );
}
}
https://stackoverflow.com/questions/49711678
复制相似问题