我有一个代码可以使用 cronjob 定期更改元值。该鳕鱼位于 WordPress 之外。它仅更新前 8 个产品。
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'meta_key' => '_sale_price',
);
$the_query = new WP_Query($args);
while($the_query->have_posts()) : $the_query->the_post();
update_post_meta(get_the_ID(), "_regular_price", '$new_value');
endwhile;
如何更改所有帖子元值?
最佳答案
在您的代码中update_post_meta(get_the_ID(), "_regular_price", '$new_value');
$new_value
在单引号内,php 不会将其视为变量。它应该用双引号引起来,以便 php 转换该变量,然后您的更新函数应该按预期工作。
关于php - WordPress 查询更新未更新所有帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33123795/