• I have the CPT “products”, with a cpt-onomy, but I’m having a really hard time trying to make the terms selected by default.
    For testing purposes I added a hook so that every time you save the CPT, only the term with the id “9” should be set. But that doesn’t work.

    function my_custom_save_post( $post_id ) {
        global $cpt_onomy;
    
        // set the ID of one of the taxonomy 
        $cat_ids = array( 9 );
        wp_set_object_terms( $post_id, $cat_ids, 'products' );
    }
    add_action( 'save_post_products', 'my_custom_save_post' , 10, 3 );

    If I do the same with a standard taxonomy, it works fine.
    Any idea what could be the problem?
    Thanks

  • The topic ‘Set taxonomies terms by default to true’ is closed to new replies.