我有一个类别,大约有3500个帖子。2.500未发布,但保存为草稿。
我想取消发布这一类别中剩余的1000篇帖子。也许我以后会想删除所有的帖子。
我该怎么做?
我有一个类别,大约有3500个帖子。2.500未发布,但保存为草稿。
我想取消发布这一类别中剩余的1000篇帖子。也许我以后会想删除所有的帖子。
我该怎么做?
您需要获取类别中已发布的帖子,然后运行wp_update_post()
插入新状态。下面是一个快速函数。我将其附加到admin init。我也会在你的状态更新后关闭它。
function wpse_55018_get_update() {
for( $i = 0; $i < 10; $i++ ) { // Runs this loop 10 times
$args = array(
\'post_status\' => \'published\',
\'cat\' => 23, // Use Category ID here.
\'posts_per_page\' => 100, // Lets just do 100 at a time so we don\'t blow up your server
\'no_found_rows\' => true, // We don\'t need to paginate.
\'update_post_meta_cache\' => false, // We don\'t need post meta either.
);
$posts = get_posts( $args );
if ( !$posts ) return; // Breaks out of the function if there are no posts.
foreach ( $posts as $post ) {
print_r( wpse_54018_change_status( $post->ID ) );
}
}
}
functionwpse_54018_change_status( $post_id ) {
$updated_post = array();
$updated_post[\'ID\'] = (int) $post_id;
$updated_post[\'post_status\'] = \'draft\';
wp_update_post( $updated_post );
return $post_id .\' Has been Updated\';
}
add_action( \'admin_init\', \'wpse55018_get_update\' ); This will run the next an admin page is loaded.
我有一个Wordpress模板。php页面。该页面有“下一页”和“上一页”箭头,允许浏览所有帖子。我想将某些类别的帖子排除在“下一个”和“上一个”计算中。我有以下代码: // in single.php next_post_link( \'%link\', \'← Previous\', false, \'11 and 13 and 15\'); 这应该会显示到下一篇文章的链接。第11、13和15类的职位不应按照the $ignore_categories para