这对我有用,但我需要日期条件。如果修改后的日期是10天前,那是真的,否则是假的,我怎么能做到呢?
add_action('init', 'automatically_trash_sold_items_in_woocommerce_callback');
function automatically_trash_sold_items_in_woocommerce_callback() {
// Get any existing copy of our transient data
if ( false === ( $automatically_trash_sold_items_in_woocommerce = get_transient( 'automatically_trash_sold_items_in_woocommerce' ) ) ) {
// It wasn't there, so regenerate the data and save the transient
global $wpdb;
$wpdb->query( "UPDATE {$wpdb->posts} P JOIN {$wpdb->postmeta} PM ON P.ID = PM.post_id SET P.post_status='trash' WHERE P.post_type='product' and PM.meta_key='_stock_status' AND PM.meta_value='outofstock'");
set_transient( 'automatically_trash_sold_items_in_woocommerce', true, 12 * HOUR_IN_SECONDS );
}
}发布于 2022-06-25 07:29:00
您可以遵循自动删除草稿wp函数https://developer.wordpress.org/reference/functions/wp_delete_auto_drafts/的相同概念。
这将过滤超过10天前修改日期的帖子。
add_action('init', 'automatically_trash_sold_items_in_woocommerce_callback');
function automatically_trash_sold_items_in_woocommerce_callback() {
// Get any existing copy of our transient data
if ( false === ( $automatically_trash_sold_items_in_woocommerce = get_transient( 'automatically_trash_sold_items_in_woocommerce' ) ) ) {
// It wasn't there, so regenerate the data and save the transient
global $wpdb;
$wpdb->query( "UPDATE {$wpdb->posts} P JOIN {$wpdb->postmeta} PM ON P.ID = PM.post_id SET P.post_status='trash' WHERE P.post_type='product' and PM.meta_key='_stock_status' AND PM.meta_value='outofstock' AND DATE_SUB( now(), INTERVAL 10 DAY ) > p.post_modified");
set_transient( 'automatically_trash_sold_items_in_woocommerce', true, 12 * HOUR_IN_SECONDS );
}https://stackoverflow.com/questions/72749347
复制相似问题