Category change after set time
-
Hi.
For our category, currently at the movies (film-nu-in-de-zaal), we would like to implement a function that after 6 weeks this changes to the category movie reviews (film-recensies). (For testing purpouses the time is set to 11 minutes, since anything lower than this won’t execute the update function.)
Using an example on stackoverflow and the codex I managed to get this far, 3/4th of the code works. The code fires at the set time and the category is removed.
Sadly… the category is set to “uncategorized” every single time. We have tried implementing the numbers, ditching the old and new category variables but nothing seems to do the trick.
Can anyone help us out here ?
Thanks in advance
// 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 ) { //categories $old_cat = get_cat_ID( 'film-nu-in-de-zaal' ); $new_cat = get_cat_ID( 'film-recensies' ); // 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); } }
- The topic ‘Category change after set time’ is closed to new replies.