You’ve got a number of issues with you code…
if (is_array($expirationtime))is redundant becauseget_post_metawill always return an array if the third parameter is false.implode($expirationtime);requires a separator, e.g.implode(' ', $expirationtime);.strtotimecan fail to parse your input resulting in a false value. You will get an error when trying to performfalse - time().- You’re defining a function with
function set_new_category() {}but not using it. wp_set_post_categoriesis for setting terms for the category taxonomy. For custom taxonomies, usewp_set_post_termsinstead.
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.