wp_get_post_terms( $post_id, $taxonomy, $args )
expects third param to be an array of arguments.
Params
$post_id (integer) (optional) The Post ID Default: 0
$taxonomy
(string|array) (optional) The taxonomy for which to retrieve terms.
Defaults to post_tag. Default: ‘post_tag’$args (array) (optional)
Overwrite the defaults Default: array
My guess is that $old_term
is being set to wp_get_post_terms
response of a WP_Error. So it is always true when you’re checking it.
Response
(array|WP_Error) An array of taxonomy terms, or empty array if no
terms are found. WP_Error if $taxonomy does not exist. See
is_wp_error() for more information.
You can verify the response is good with something like:
if( is_array( $old_term ) && ! empty( $old_term ) ) {
//do stuff
}
If you are trying be sure that the post has the taxonomy term building_reservations
from the taxonomy of event_category
, perhaps something close to this will work:
$old_term = wp_get_post_terms( $post_id, $em_taxonomy );
if( is_array( $old_term ) && ! empty( $old_term ) ) {
if ( in_array( 'building_reservations', $old_term ) {
wp_set_post_categories( $post_id, $new_category, $append = true );
}
}