• I’m sorry, I speak a little English.

    $x = wp_insert_term( 'Duper', 'category' );
    // $x = array ( 'term_id'=> 692, 'term_taxonomy_id'=> 692 );

    The term_id and the term_taxonomy_id always the same?

    Which one should I use as a category ID?

    Example:

    wp_insert_post( array( 'post_category'=> array( $x [ 'term_id' ] ) ) );
    // OR
    wp_insert_post( array( 'post_category'=> array( $x [ 'term_taxonomy_id' ] ) ) );

    Thanks.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    They are almost always the same on most sites, but’s not guaranteed. I forget why they sometimes are not the same, but it can happen. Functions expecting a category ID want the “term_id” value. “term_taxonomy_id” is almost never passed as an argument in practical usage, though it’s a possible query var if you so desired, like for the “tax_query” args of WP_Query class.

    Best I can recall, but might be wrong, is the two came into play years back when WP used the same term name in different taxonomies. More recently, identical term names get separate IDs. So assuming they may not be the same would be for legacy support, which is important to maintain to the extent possible.

Viewing 1 replies (of 1 total)
  • The topic ‘The term_id and the term_taxonomy_id always the same?’ is closed to new replies.