[WordPress][B2优化]批量修改文章下载权限

用前注意:
1、使用此代码前,先备份一下数据库,以免出现意外造成数据损坏。
2、此代码复制到 Pages/test.php 中保存,然后使用 你的网址+/test 去访问一下,显示成功后再 删掉 保存即可,记得删掉哦!!!

代码附件了,纯小白慎行哈!!!

//使用此代码前,先备份一下数据库,以免出现意外造成数据损坏。
//此代码复制到 Pages/test.php 中保存,然后使用 你的网址+/test 去访问一下,显示成功后再 删掉 保存即可。
$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 '没有文章';
}
© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容