Update table wp_term_taxonomy.count after INSERT INTO via SQL

You can just run the wp_update_term_count_now php function after doing this: https://developer.wordpress.org/reference/functions/wp_update_term_count_now/ Which calls the private _update_post_term_count https://developer.wordpress.org/reference/functions/_update_post_term_count/ If you look at the source of that you will see how term counts are updated (which is done when you save a post on backend): function _update_post_term_count( $terms, $taxonomy ) { global $wpdb; $object_types = (array) … Read more

How Parent Taxonomy automatically added to the post when using `wp_set_object_terms()`?

You can use get_ancestors() to get parents and grandparents etc. of a term, then use that in wp_set_object_terms(): $term_id = 12; // Get array of term parents. $terms = get_ancestors( $term_id, ‘topic’ ); // Include original term in array. $terms[] = $term_id; // Add parents and original term to post. wp_set_object_terms( $post_id, $terms, ‘topic’, true … Read more

If Custom Taxonomy

get_the_term_list() returns a string of HTML for the list of taxonomy terms on the given post. Without giving values in the optional arguments it would look like this: <a href=”http://example.com/type/roast/” rel=”tag”>Roast</a> <a href=”http://example.com/type/type2/” rel=”tag”>Type 2</a> So $type == ‘roast’ would not be true because the value isn’t anything close to ‘roast’. Even if it returned … Read more