indexable_builder = $indexable_builder; $this->indexable_repository = $indexable_repository; } /** * Builds on-the-fly public indexables in a paginated manner. * * @codeCoverageIgnore -- This is covered by dedicated integration tests. * * @param int $page The page number. * @param int $page_size The number of items per page. * @param string $post_type The post type to filter by. * * @return array The array of public indexables. */ public function get( int $page, int $page_size, string $post_type ): array { $query = new WP_Query( [ 'post_type' => $post_type, 'post_status' => 'publish', 'posts_per_page' => $page_size, 'paged' => $page, 'fields' => 'ids', 'no_found_rows' => false, ], ); if ( ! $query instanceof WP_Query ) { return []; } $post_ids = isset( $query->posts ) && \is_array( $query->posts ) ? $query->posts : []; $public_indexables = []; foreach ( $post_ids as $post_id ) { $indexable = $this->indexable_repository->find_by_id_and_type( $post_id, 'post' ); if ( $indexable !== null && ( $indexable->is_public === true || $indexable->is_public === null ) ) { if ( empty( $indexable->id ) ) { $indexable->id = $post_id; } $public_indexables[] = $indexable; } } return $public_indexables; } }