我有下面的代码,可以在预定的活动后更改常规帖子的一个类别。它工作得很好。然而,我需要它来定位WooCommerce产品类别。我的问题:有没有办法调整我当前的代码以适应自定义的帖子类型?
// runs when a post is published
add_action( \'publish_post\', \'wcsri_schedule_post_check\' );
function wcsri_schedule_post_check( $post_id ) {
// set the time when the event should be scheduled
$timestamp = strtotime( \'+7 days\' );
// Schedule the event
wp_schedule_single_event( $timestamp, \'wcsri_check_post\', array( $post_id )
);
}
// a custom hook to schedule
add_action( \'wcsri_check_post\', \'wcsri_check_post_cats\', 10, 1 );
// replace post categories
function wcsri_check_post_cats( $post_id ) {
//categories
$old_cat = get_the_terms($post->ID, "foo");
$new_cat = get_the_terms($post->ID, "bar");
// check for the old category
if ( has_category( $old_cat, $post_id ) ) {
// update post with new category
$args = array(
\'ID\' => $post_id,
\'post_category\' => array( $new_cat ),
);
wp_update_post($args);
}
}