Schedule category change on set time in future not working

I created a function that adds 11 minutes to the publish date, after which the category should change from “At the movies”(film-nu-in-de-zaal) to “movie reviews”(film-recensies).

The 11 minutes is obviously for testing, the idea is to change that to 4 weeks once I get it working.

Thing is, the function I have below works, but as soon as I add the if has category function it doesn’t. Otherwise the function will do the trick for any article with any category, so it has to be a specific category.

I’ve been looking where I went wrong but can’t figure it out, anyone here who can help me find the solution ?

// runs when a post is published
add_action( ‘publish_post’, ‘schedule_post_check’ );

function schedule_post_check( $post_id ) {

// Schedule the event
wp_schedule_single_event( time() + 660, ‘check_post’, array( $post_id ) );
}

// a custom hook to schedule
add_action( ‘check_post’, ‘check_post_cats’, 10, 1 );

// replace post categories

function check_post_cats( $post_id ) {
if( has_category( array(39), $post_id) ){
$cat_ids = array( 12 );
$term_taxonomy_ids = wp_set_object_terms( $post_id, $cat_ids, ‘category’ );
}
}

Read more here:: Schedule category change on set time in future not working

Leave a Reply

Your email address will not be published. Required fields are marked *