WordPress.org

Ready to get started?Download WordPress

Forums

How to Obtain Custom Taxonomy ID and Convert to Int? (1 post)

  1. ithacaindy
    Member
    Posted 1 year ago #

    I'm having trouble obtaining the id of my custom taxonomy term, then converting it into a int to be used in wp_set_object_terms().

    Here's the code I'm using:

    function default_cat($post_ID)
    {
        $terms = get_the_terms( $post->ID , 'control' );
        if($terms) {
    	foreach( $terms as $term ) {
            $cat_ids = array($term->term_id);
            $cat_ids = array_map('intval', $cat_ids );
            }
    }
    
        wp_set_object_terms( $post_ID, $cat_ids, 'category' );
    }
    add_action('publish_post', 'default_cat');

    I keep getting an error about the second argument in array_map() not being an array. What am I doing wrong?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.