【发布时间】:2021-04-24 02:00:34
【问题描述】:
我有一个名为 Project 的自定义帖子。
当发布日期超过 7 天时,我需要使用 100 自动更新字段。
我在 function.php 中尝试了以下 coed,但它不会自动更新字段。
请告诉我如何修复代码?
function update_active_based_on_date() {
// query to get all custom posts - project
$args = array(
'post_type' => 'project',
'posts_per_page' => -1
);
$query = new WP_Query($args);
// if posts are returned and more than 7days, update infosubmit field
if ($query->have_posts()) {
global $post;
$timestamp = get_the_time( 'U', $post->ID );
$diff = current_time('timestamp') - $timestamp;
while ($query->have_posts() && $diff > 604800) {
$query->the_post();
$field_key = "field_60836f942ae12";
$value = "100";
update_field($field_key, $value, $post->ID);
} // end while have_posts
wp_reset_postdata();
} // end if have_posts
} // end function
谢谢。
【问题讨论】:
标签: php wordpress advanced-custom-fields