示例,批量修改woocommerce产品中的排序字段为0:
$args = array(
'numberposts' => -1,
'post_type' => 'product',
'post_status' => 'any',
'product_tag' => 'aaa',
);
$postslists = get_posts( $args );
foreach ($postslists as $postslist) {
$post_id = $postslist->ID;
$post_menu_order = $postslist->menu_order;
var_dump($post_menu_order);
if($post_menu_order != 0){
wp_update_post( array('ID'=> $post_id,'menu_order'=> '0') );
}
}
上面的代码中post_type是文章类型,默认的为post,product_tag为分类法;是woocommerce产品标签的分类法,默认的为taxonomy。如果要修改自定义字段,可以不用wp_update_post改用update_post_meta。
© 版权声明
THE END