| @@ -67,16 +67,21 @@ | ||
| 67 | 67 | $is_public_only = $params[ self::IS_PUBLIC_KEY ] ?? true; |
| 68 | 68 | $post_types = $this->get_post_types_from_params( $request ); |
| 69 | 69 | |
| 70 | 70 | $query_args = [ |
| 71 | - 'post_type' => array_keys( $post_types ), | |
| 72 | - 'numberposts' => $post_count, | |
| 73 | - 'suppress_filters' => false, | |
| 74 | - 'custom_search' => true, | |
| 75 | - 'post_status' => $is_public_only ? 'publish' : 'any', | |
| 76 | - 'orderby' => 'modified', | |
| 77 | - 'order' => 'DESC', | |
| 71 | + 'post_type' => array_keys( $post_types ), | |
| 72 | + 'numberposts' => $post_count, | |
| 73 | + 'suppress_filters' => false, | |
| 74 | + 'custom_search' => true, | |
| 75 | + 'post_status' => $is_public_only ? 'publish' : 'any', | |
| 76 | + 'orderby' => 'modified', | |
| 77 | + 'order' => 'DESC', | |
| 78 | 78 | ]; |
| 79 | + | |
| 80 | + // for non-admins (contributors), filter by author for private posts | |
| 81 | + if ( ! $is_public_only && ! current_user_can( 'read_private_posts' ) ) { | |
| 82 | + $query_args['author'] = get_current_user_id(); | |
| 83 | + } | |
| 79 | 84 | |
| 80 | 85 | if ( ! empty( $term ) ) { |
| 81 | 86 | $query_args['search_term'] = $term; |
| 82 | 87 | $query_args[ self::SEARCH_IN_CONTENT_KEY ] = $params[ self::SEARCH_IN_CONTENT_KEY ] ?? false; |