Ticket #18986: 18986.diff
File 18986.diff, 4.1 KB (added by , 13 years ago) |
---|
-
wp-includes/taxonomy.php
2450 2450 call_user_func($taxonomy->update_count_callback, $terms, $taxonomy); 2451 2451 } else { 2452 2452 // Default count updater 2453 _update_ post_term_count( $terms, $taxonomy );2453 _update_generic_term_count( $terms, $taxonomy ); 2454 2454 } 2455 2455 2456 2456 clean_term_cache($terms, '', false); … … 2842 2842 function _update_post_term_count( $terms, $taxonomy ) { 2843 2843 global $wpdb; 2844 2844 2845 $object_types = is_array($taxonomy->object_type) ? $taxonomy->object_type : array($taxonomy->object_type);2845 $object_types = (array) $taxonomy->object_type; 2846 2846 2847 2847 foreach ( $object_types as &$object_type ) 2848 2848 list( $object_type ) = explode( ':', $object_type ); 2849 2849 2850 2850 $object_types = array_unique( $object_types ); 2851 $object_types = esc_sql($object_types);2852 2851 2852 if ( $check_attachments = array_search( 'attachment', $object_types ) ) 2853 unset( $object_types[ $check_attachments ] ); 2854 $check_attachments = (bool) $check_attachments; 2855 2856 if ( $object_types ) 2857 $object_types = array_filter( $object_types, 'post_type_exists' ); 2858 2853 2859 foreach ( (array) $terms as $term ) { 2860 $count = 0; 2854 2861 2855 2862 // Attachments can be 'inherit' status, we need to base count off the parent's status if so 2856 if ( in_array( 'attachment', $object_types ) ) 2857 $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts p1 WHERE p1.ID = $wpdb->term_relationships.object_id AND ( post_status = 'publish' OR ( post_status = 'inherit' AND post_parent > 0 AND ( SELECT post_status FROM $wpdb->posts WHERE ID = p1.post_parent ) = 'publish' ) ) AND post_type IN ('" . implode("', '", $object_types) . "') AND term_taxonomy_id = %d", $term ) ); 2858 elseif ( post_type_exists( $object_type ) ) 2859 $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 ) ); 2860 else 2861 $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term ) ); 2863 if ( $check_attachments ) 2864 $count += (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts p1 WHERE p1.ID = $wpdb->term_relationships.object_id AND ( post_status = 'publish' OR ( post_status = 'inherit' AND post_parent > 0 AND ( SELECT post_status FROM $wpdb->posts WHERE ID = p1.post_parent ) = 'publish' ) ) AND post_type = 'attachment' AND term_taxonomy_id = %d", $term ) ); 2862 2865 2866 if ( $object_types ) 2867 $count += (int) $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 ) ); 2868 2869 2863 2870 do_action( 'edit_term_taxonomy', $term, $taxonomy ); 2864 2871 $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) ); 2865 2872 do_action( 'edited_term_taxonomy', $term, $taxonomy ); 2866 2873 } 2867 2874 } 2868 2875 2876 /** 2877 * Will update term count based on number of objects. 2878 * 2879 * Default callback for the link_category taxonomy. 2880 * 2881 * @package WordPress 2882 * @subpackage Taxonomy 2883 * @since 3.3.0 2884 * @uses $wpdb 2885 * 2886 * @param array $terms List of Term taxonomy IDs 2887 * @param object $taxonomy Current taxonomy object of terms 2888 */ 2889 function _update_generic_term_count( $terms, $taxonomy ) { 2890 global $wpdb; 2869 2891 2892 foreach ( (array) $terms as $term ) { 2893 $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term ) ); 2894 2895 do_action( 'edit_term_taxonomy', $term, $taxonomy ); 2896 $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) ); 2897 do_action( 'edited_term_taxonomy', $term, $taxonomy ); 2898 } 2899 } 2900 2870 2901 /** 2871 2902 * Generates a permalink for a taxonomy term archive. 2872 2903 *