From 7697822c5d2937a27235f5b92bd8092e6c54cf1f Mon Sep 17 00:00:00 2001 From: Joshua Roy Date: Wed, 19 Jul 2017 15:39:35 -0400 Subject: [PATCH] Fixing search --- grandchild-functions.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/grandchild-functions.php b/grandchild-functions.php index d9f8e62..dbe7941 100644 --- a/grandchild-functions.php +++ b/grandchild-functions.php @@ -70,7 +70,16 @@ function gradschool_breadcrumbs(){ function filter_search($query) { if ($query->is_search) { - $query->set('post_type', array('post', 'courses')); + // Get post types + $post_types = get_post_types(array('public' => true, 'exclude_from_search' => false), 'objects'); + $searchable_types = array(); + // Add available post types + if( $post_types ) { + foreach( $post_types as $type) { + $searchable_types[] = $type->name; + } + } + $query->set( 'post_type', $searchable_types ); }; return $query; };