'product',
'posts_per_page' => -1,
);
$products = new WP_Query( $args );
if ( $products->have_posts() ) {
echo 'Data serwera: ' . $current_date . '
';
while ( $products->have_posts() ) {
$products->the_post();
$product_id = get_the_ID();
$product_title = get_the_title( $product_id );
$acf_field_value = get_field( 'end_date_of_the_offer', $product_id );
$acf_date_object = DateTime::createFromFormat('Y-m-d', $acf_field_value);
if ($acf_date_object !== false) {
$acf_field_value = $acf_date_object->format('Y-m-d');
echo 'Product ID: ' . $product_id . '
';
echo 'Product Title: ' . $product_title . '
';
echo 'KoĊcowa data oferty: ' . $acf_field_value . '
';
echo '-----------------------------------------------------
';
if($acf_field_value && $acf_field_value < $current_date) {
wp_update_post(array(
'ID' => $product_id,
'post_status' => 'draft',
));
delete_field('end_date_of_the_offer', $product_id);
}
}
}
wp_reset_postdata();
}
?>