$query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts}"; $query .= " LEFT JOIN {$wpdb->postmeta} as eventStart ON( {$wpdb->posts}.ID = eventStart.post_id AND eventStart.meta_key = '_EventStartDate') "; $query .= " WHERE post_type = %s"; if ('readable' == $perm && is_user_logged_in()) { $post_type_object = get_post_type_object($type); if (!current_user_can($post_type_object->cap->read_private_posts)) { $cache_key .= '_' . $perm . '_' . $user->ID; $query .= " AND (post_status != 'private' OR ( post_author = '{$user->ID}' AND post_status = 'private' ))"; } } $query .= ' GROUP BY post_status'; $count = wp_cache_get($cache_key, 'counts'); $count = false; if (false !== $count) { return $count; } $count = $wpdb->get_results($wpdb->prepare($query, $type), ARRAY_A); $stats = array(); foreach (get_post_stati() as $state) { $stats[$state] = 0; } foreach ((array) $count as $row) { $stats[$row['post_status']] = $row['num_posts']; } $stats = (object) $stats; wp_cache_set($cache_key, $stats, 'counts'); return $stats; } } TribeEventsAdminList::init(); }