
什么是PHP Worker及应该如何使用
_update_term_count_on_transition_post_status ( $new_status, $old_status, $post )
_update_term_count_on_transition_post_status: 当一个文章从一个状态过渡到另一个状态时,这个函数更新特定分类法的术语计数。它用于确保当文章被添加、删除或修改时,分类法的术语计数是准确的。
当一个文章的状态改变时,更新自定义分类法的术语计数。
例如,默认的文章术语计数(针对自定义分类法)不包括 私密/草稿帖。
function _update_term_count_on_transition_post_status( $new_status, $old_status, $post ) { // Update counts for the post's terms. foreach ( (array) get_object_taxonomies( $post->post_type ) as $taxonomy ) { $tt_ids = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'tt_ids' ) ); wp_update_term_count( $tt_ids, $taxonomy ); } }