Changeset 19035 for trunk/wp-includes/taxonomy.php
- Timestamp:
- 10/21/2011 09:38:14 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/taxonomy.php
r19031 r19035 2450 2450 call_user_func($taxonomy->update_count_callback, $terms, $taxonomy); 2451 2451 } else { 2452 // Default count updater 2453 _update_post_term_count( $terms, $taxonomy ); 2452 $object_types = (array) $taxonomy->object_type; 2453 foreach ( $object_types as &$object_type ) { 2454 if ( 0 === strpos( $object_type, 'attachment:' ) ) 2455 list( $object_type ) = explode( ':', $object_type ); 2456 } 2457 2458 if ( $object_types == array_filter( $object_types, 'post_type_exists' ) ) { 2459 // Only post types are attached to this taxonomy 2460 _update_post_term_count( $terms, $taxonomy ); 2461 } else { 2462 // Default count updater 2463 _update_generic_term_count( $terms, $taxonomy ); 2464 } 2454 2465 } 2455 2466 … … 2843 2854 global $wpdb; 2844 2855 2845 $object_types = is_array($taxonomy->object_type) ? $taxonomy->object_type : array($taxonomy->object_type);2856 $object_types = (array) $taxonomy->object_type; 2846 2857 2847 2858 foreach ( $object_types as &$object_type ) 2848 2859 list( $object_type ) = explode( ':', $object_type ); 2849 2860 2850 2861 $object_types = array_unique( $object_types ); 2851 $object_types = esc_sql($object_types); 2862 2863 if ( false !== ( $check_attachments = array_search( 'attachment', $object_types ) ) ) { 2864 unset( $object_types[ $check_attachments ] ); 2865 $check_attachments = true; 2866 } 2867 2868 if ( $object_types ) 2869 $object_types = esc_sql( array_filter( $object_types, 'post_type_exists' ) ); 2852 2870 2853 2871 foreach ( (array) $terms as $term ) { 2872 $count = 0; 2854 2873 2855 2874 // 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 else2861 $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term ) ); 2862 2875 if ( $check_attachments ) 2876 $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 ) ); 2877 2878 if ( $object_types ) 2879 $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 ) ); 2880 2881 2863 2882 do_action( 'edit_term_taxonomy', $term, $taxonomy ); 2864 2883 $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) ); … … 2867 2886 } 2868 2887 2888 /** 2889 * Will update term count based on number of objects. 2890 * 2891 * Default callback for the link_category taxonomy. 2892 * 2893 * @package WordPress 2894 * @subpackage Taxonomy 2895 * @since 3.3.0 2896 * @uses $wpdb 2897 * 2898 * @param array $terms List of Term taxonomy IDs 2899 * @param object $taxonomy Current taxonomy object of terms 2900 */ 2901 function _update_generic_term_count( $terms, $taxonomy ) { 2902 global $wpdb; 2903 2904 foreach ( (array) $terms as $term ) { 2905 $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term ) ); 2906 2907 do_action( 'edit_term_taxonomy', $term, $taxonomy ); 2908 $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) ); 2909 do_action( 'edited_term_taxonomy', $term, $taxonomy ); 2910 } 2911 } 2869 2912 2870 2913 /**
Note: See TracChangeset
for help on using the changeset viewer.