wp_update_term_count()
Updates the amount of terms in taxonomy.
If there is a taxonomy callback applied, then it will be called for updating the count.
The default action is to count what the amount of terms have the relationship of term ID. Once that is done, then update the database.
No Hooks.
Return
true|false
. If no terms will return false, and if successful will return true.
Usage
wp_update_term_count( $terms, $taxonomy, $do_deferred );
- $terms(int|array) (required)
- The term_taxonomy_id of the terms.
- $taxonomy(string) (required)
- The context of the term.
- $do_deferred(true|false)
- Whether to flush the deferred term counts too.
Default: false
Examples
#1 Updating the number of posts in categories
Let's update the number of posts in categories 12 and 13, for example when a new post has been added. Such an update is done by function wp_insert_post() by calling wp_set_object_terms().
wp_update_term_count( [ 12, 13 ], 'category' );
Changelog
Since 2.3.0 | Introduced. |