2524 | | foreach ( (array) $private_states as $state ) |
2525 | | $where .= current_user_can( $read_private_cap ) ? " OR $wpdb->posts.post_status = '$state'" : " OR $wpdb->posts.post_author = $user_ID AND $wpdb->posts.post_status = '$state'"; |
| 2524 | $readable_post_types = array(); |
| 2525 | |
| 2526 | foreach ( get_post_types( array( 'exclude_from_search' => false ) ) as $pt ) { |
| 2527 | // get the post type object |
| 2528 | $pt_object = get_post_type_object($pt); |
| 2529 | // checks if the user can read private posts fo this post type |
| 2530 | if ( $pt_object && current_user_can($pt_object->cap->read_private_posts)) |
| 2531 | $readable_post_types[] = $pt; |
| 2532 | } |
| 2533 | if ($readable_post_types) { |
| 2534 | $where .= " OR ($wpdb->posts.post_status = 'private' AND post_type IN ('" . implode("','", $readable_post_types) . "') )"; |
| 2535 | } else { |
| 2536 | foreach ( (array) $private_states as $state ) |
| 2537 | $where .= $wpdb->prepare(" OR $wpdb->posts.post_author = %d AND $wpdb->posts.post_status = %s", $user_ID, $state); |
| 2538 | } |
| 2539 | |