Change custom taxonomy after certain time – CPT template

You’ve got a number of issues with you code…

  1. if (is_array($expirationtime)) is redundant because get_post_meta will always return an array if the third parameter is false.
  2. implode($expirationtime); requires a separator, e.g. implode(' ', $expirationtime);.
  3. strtotime can fail to parse your input resulting in a false value. You will get an error when trying to perform false - time().
  4. You’re defining a function with function set_new_category() {} but not using it.
  5. wp_set_post_categories is for setting terms for the category taxonomy. For custom taxonomies, use wp_set_post_terms instead.

With all of the above fixed, you should end up with something like…

$expiration_time = get_post_meta( $post->ID, 'expiration', false );

if ( count( $expiration_time ) ) {

    $expire_string = implode( ' ', $expiration_time );
    $expire_timestamp = strtotime( $expire_string );

    // Ensure the timestamp parsed correctly.
    if ( $expire_timestamp ) {
        $seconds_between = $expire_timestamp - time();

        if ( $secondsbetween >= 0 ) {
            echo 'This post will expire on ' . $expire_string;
            the_content();
        } else {
            wp_set_post_terms( $post->ID, [ 368 ], 'custom-status', true );
        }
    }

}

This isn’t a complete answer but should definitely point you in the right direction.