2855 | | // 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 ) ); |
| 2855 | $count = 0; |
| 2856 | unset( $object_type ); |
| 2857 | foreach ( $object_types as $object_type ) { |
| 2858 | // Attachments can be 'inherit' status, we need to base count off the parent's status if so |
| 2859 | if ( 'attachment' == $object_type ) |
| 2860 | $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 = %s AND term_taxonomy_id = %d", $object_type, $term ) ); |
| 2861 | elseif ( post_type_exists( $object_type ) ) |
| 2862 | $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 = %s AND term_taxonomy_id = %d", $object_type, $term ) ); |
| 2863 | else |
| 2864 | $count += $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term ) ); |
| 2865 | } |