File tree Expand file tree Collapse file tree 1 file changed +17
-7
lines changed
Expand file tree Collapse file tree 1 file changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -358,6 +358,22 @@ public function get_search_args() {
358358 return $ args ;
359359 }
360360
361+ /**
362+ * Get search post types.
363+ *
364+ * @param array $request HTTP request variables.
365+ * @return mixed
366+ */
367+ public function get_valid_search_post_types ( $ request ) {
368+ if ( is_array ( $ request ['type ' ] ) && ! empty ( $ request ['type ' ] ) ) {
369+ return array_map ( 'sanitize_text_field ' , $ request ['type ' ] );
370+ } elseif ( $ request ['type ' ] ) {
371+ return sanitize_text_field ( $ request ['type ' ] );
372+ } else {
373+ return $ this ->post_types_to_search ();
374+ }
375+ }
376+
361377 /**
362378 * Search posts.
363379 *
@@ -371,16 +387,10 @@ public function search_posts( $request ) {
371387 if ( isset ( $ request ['s ' ] ) ) :
372388 $ filter = [
373389 'posts_per_page ' => -1 ,
374- 'post_type ' => $ this ->post_types_to_search ( ),
390+ 'post_type ' => $ this ->get_valid_search_post_types ( $ request ),
375391 's ' => sanitize_text_field ( $ request ['s ' ] ),
376392 ];
377393
378- if ( is_array ( $ request ['type ' ] ) ) {
379- $ filter ['post_type ' ] = array_map ( 'sanitize_text_field ' , $ request ['type ' ] );
380- } else {
381- $ filter ['post_type ' ] = sanitize_text_field ( $ request ['type ' ] );
382- }
383-
384394 // Get posts.
385395 $ posts = get_posts ( $ filter );
386396
You can’t perform that action at this time.
0 commit comments