custom post types – How to use wp_set_object_terms depending on page ID?

Question

The function to set custom term works fine.

add_action( 'save_post', 'set_custom_term', 30, 2 );

function set_custom_term( $post_id, $post ) {
    wp_set_object_terms($post_id, 'guitar', 'instrument',true); 
}

I need to set different terms depending on page ID. The following code didn’t worked.

add_action( 'save_post', 'set_custom_term', 30, 2 );

function set_custom_term( $post_id, $post ) {
    if (is_page(22)){
        wp_set_object_terms($post_id,'guitar', 'instrument', true); 
    }
}

0
Kim Caspe 3 weeks 2023-01-04T11:27:41-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse