375 | | $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" ); |
| 375 | $cache_key = "count_user_{$post_type}_{$userid}"; |
| 376 | |
| 377 | if ( $public_only ) { |
| 378 | $cache_group = 'user_posts_count_public'; |
| 379 | } else { |
| 380 | $cache_group = 'user_posts_count'; |
| 381 | } |
| 382 | |
| 383 | $count = wp_cache_get( $cache_key, $cache_group ); |
| 384 | |
| 385 | if ( false === $count ) { |
| 386 | $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" ); |
| 387 | wp_cache_add( $cache_key, $count, $cache_group ); |
| 388 | } |
412 | | $userlist = implode( ',', array_map( 'absint', $users ) ); |
413 | | $where = get_posts_by_author_sql( $post_type, true, null, $public_only ); |
414 | | |
415 | | $result = $wpdb->get_results( "SELECT post_author, COUNT(*) FROM $wpdb->posts $where AND post_author IN ($userlist) GROUP BY post_author", ARRAY_N ); |
416 | | foreach ( $result as $row ) { |
417 | | $count[ $row[0] ] = $row[1]; |
| 425 | foreach ( $users as $user_id ) { |
| 426 | $count[ $user_id ] = count_user_posts( $user_id, $post_type, $public_only ); |