代码使用教程
此隐藏内容仅限VIP查看升级VIP
具体代码
$arg = array(
'post_type'=>'post',//文章形式是post
'post_status'=>'publish',//文章状态是已发布
'posts_per_page'=>-1//所有文章,如果文章数量过多(几万篇),可能速度很慢
);
$the_query = new WP_Query($arg);
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
$id = get_the_id();
$res = false;
//要设置的文章ID范围
if($id >=26925 && $id <= 37199){
$downs = get_post_meta($id,'b2_single_post_download_group',true);
if(!empty($downs)){
$save = false;
foreach ($downs as $k => $v) {
if(isset($downs[$k]['rights'])){
$downs[$k]['rights'] = 'vip1|free';
$save = true;
}
}unset($v);
if($save){
update_post_meta($id,'b2_single_post_download_group',$downs);
}
}
}
}
echo '完成';
wp_reset_postdata();
} else {
echo '没有文章';
}