Make WordPress Core

Changeset 13625


Ignore:
Timestamp:
03/09/2010 10:48:18 AM (14 years ago)
Author:
dd32
Message:

Add custom post_type support to _update_post_term_coun(). Props momo360modena. Fixes #12348

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/taxonomy.php

    r13608 r13625  
    18571857
    18581858    $tt_id = $wpdb->get_var( $wpdb->prepare( "SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d", $taxonomy, $term_id) );
    1859     do_action( 'edit_term_taxonomy', $tt_id );
     1859    do_action( 'edit_term_taxonomy', $tt_id, $taxonomy );
    18601860    $wpdb->update( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent' ), array( 'term_taxonomy_id' => $tt_id ) );
    18611861    do_action( 'edited_term_taxonomy', $tt_id );
     
    19551955    $taxonomy = get_taxonomy($taxonomy);
    19561956    if ( !empty($taxonomy->update_count_callback) ) {
    1957         call_user_func($taxonomy->update_count_callback, $terms);
     1957        call_user_func($taxonomy->update_count_callback, $terms, $taxonomy);
    19581958    } else {
    19591959        // Default count updater
    19601960        foreach ( (array) $terms as $term) {
    19611961            $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term) );
    1962             do_action( 'edit_term_taxonomy', $term );
     1962            do_action( 'edit_term_taxonomy', $term, $taxonomy );
    19631963            $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );
    1964             do_action( 'edited_term_taxonomy', $term );
     1964            do_action( 'edited_term_taxonomy', $term, $taxonomy );
    19651965        }
    19661966
     
    23372337
    23382338/**
    2339  * Will update term count based on posts.
     2339 * Will update term count based on object types of the current taxonomy.
    23402340 *
    23412341 * Private function for the default callback for post_tag and category
     
    23492349 *
    23502350 * @param array $terms List of Term taxonomy IDs
    2351  */
    2352 function _update_post_term_count( $terms ) {
     2351 * @param object $taxonomy Current taxonomy object of terms
     2352 */
     2353function _update_post_term_count( $terms, $taxonomy ) {
    23532354    global $wpdb;
    23542355
     2356    $object_types = is_array($taxonomy->object_type) ? $taxonomy->object_type : array($taxonomy->object_type);
     2357    $object_types = esc_sql($object_types);
     2358
    23552359    foreach ( (array) $terms as $term ) {
    2356         $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = %d", $term ) );
    2357         do_action( 'edit_term_taxonomy', $term );
     2360        $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type IN ('" . implode("', '", $object_types) . "') AND term_taxonomy_id = %d", $term ) );
     2361        do_action( 'edit_term_taxonomy', $term, $taxonomy );
    23582362        $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );
    2359         do_action( 'edited_term_taxonomy', $term );
     2363        do_action( 'edited_term_taxonomy', $term, $taxonomy );
    23602364    }
    23612365}
Note: See TracChangeset for help on using the changeset viewer.