Skip to content

Commit cd0ad3e

Browse files
committed
Revert [18783], as it breaks term relationship counts for attachment taxonomies. see #17548.
git-svn-id: https://develop.svn.wordpress.org/trunk@18809 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 8585471 commit cd0ad3e

3 files changed

Lines changed: 13 additions & 18 deletions

File tree

wp-includes/default-filters.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@
254254
add_action( 'publish_post', '_publish_post_hook', 5, 1 );
255255
add_action( 'save_post', '_save_post_hook', 5, 2 );
256256
add_action( 'transition_post_status', '_transition_post_status', 5, 3 );
257-
add_action( 'transition_post_status', '_update_term_count_on_transition_post_status', 10, 3 );
258257
add_action( 'comment_form', 'wp_comment_form_unfiltered_html_nonce' );
259258
add_action( 'wp_scheduled_delete', 'wp_scheduled_delete' );
260259
add_action( 'admin_init', 'send_frame_options_header', 10, 0 );

wp-includes/post.php

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2727,6 +2727,12 @@ function wp_publish_post($post_id) {
27272727
$post->post_status = 'publish';
27282728
wp_transition_post_status('publish', $old_status, $post);
27292729

2730+
// Update counts for the post's terms.
2731+
foreach ( (array) get_object_taxonomies('post') as $taxonomy ) {
2732+
$tt_ids = wp_get_object_terms($post_id, $taxonomy, array('fields' => 'tt_ids'));
2733+
wp_update_term_count($tt_ids, $taxonomy);
2734+
}
2735+
27302736
do_action('edit_post', $post_id, $post);
27312737
do_action('save_post', $post_id, $post);
27322738
do_action('wp_insert_post', $post_id, $post);
@@ -5305,20 +5311,4 @@ function _post_format_wp_get_object_terms( $terms ) {
53055311
}
53065312
add_filter( 'wp_get_object_terms', '_post_format_wp_get_object_terms' );
53075313

5308-
/**
5309-
* Update the custom taxonomies' term counts when a post's status is changed. For example, default posts term counts (for custom taxonomies) don't include private / draft posts.
5310-
*
5311-
* @access private
5312-
* @param string $new_status
5313-
* @param string $old_status
5314-
* @param object $post
5315-
* @since 3.3.0
5316-
*/
5317-
function _update_term_count_on_transition_post_status( $new_status, $old_status, $post ) {
5318-
// Update counts for the post's terms.
5319-
foreach ( (array) get_object_taxonomies( $post->post_type ) as $taxonomy ) {
5320-
$tt_ids = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'tt_ids' ) );
5321-
wp_update_term_count( $tt_ids, $taxonomy );
5322-
}
5323-
}
53245314
?>

wp-includes/taxonomy.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2445,7 +2445,13 @@ function wp_update_term_count_now( $terms, $taxonomy ) {
24452445
call_user_func($taxonomy->update_count_callback, $terms, $taxonomy);
24462446
} else {
24472447
// Default count updater
2448-
_update_post_term_count( $terms, $taxonomy );
2448+
foreach ( (array) $terms as $term) {
2449+
$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term) );
2450+
do_action( 'edit_term_taxonomy', $term, $taxonomy );
2451+
$wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );
2452+
do_action( 'edited_term_taxonomy', $term, $taxonomy );
2453+
}
2454+
24492455
}
24502456

24512457
clean_term_cache($terms, '', false);

0 commit comments

Comments
 (0)