{"id":11220142,"date":"2019-02-18T21:20:29","date_gmt":"2019-02-18T21:20:29","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/multiple-search-forms-with-custom-custom-post-type-type\/"},"modified":"2019-02-19T00:20:40","modified_gmt":"2019-02-19T00:20:40","slug":"multiple-search-forms-with-custom-custom-post-type-type","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/multiple-search-forms-with-custom-custom-post-type-type\/","title":{"rendered":"multiple search forms with custom custom post type type"},"content":{"rendered":"<p>Hi,<\/p>\n<p>I&#8217;ve successfully added a custom post type (people) to the main search form for my site, by adding this function in my child theme:<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<pre><code>\nadd_action( &#039;wp_enqueue_scripts&#039;, &#039;theme_enqueue_styles&#039; );\n\nadd_filter( &#039;pre_get_posts&#039;, &#039;tgm_io_cpt_search&#039; );\n\/**\n * This function modifies the main WordPress query to include an array of \n * post types instead of the default &#039;post&#039; post type.\n *\n * @param object $query  The original query.\n * @return object $query The amended query.\n *\/\nfunction tgm_io_cpt_search( $query ) {\n\t\n    if ( $query-&gt;is_search ) {\n\t$query-&gt;set( &#039;post_type&#039;, array( &#039;people&#039;, &#039;post&#039;, &#039;pages&#039; ) );\n    }\n    \n    return $query;\n<\/code><\/pre>\n<p> &#8212;&#8212;&#8212;&#8212;&#8212;- <\/p>\n<p>Unfortunately it overwrote the other search form I&#8217;m using in the people section. I want that search form to pull in the people post type only. currently both search forms are now pulling in ( &#8216;people&#8217;, &#8216;post&#8217;, &#8216;pages&#8217; ). I used Ivory search to create the people search.<\/p>\n","protected":false},"template":"","class_list":["post-11220142","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/11220142","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":1,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/11220142\/revisions"}],"predecessor-version":[{"id":11220505,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/11220142\/revisions\/11220505"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=11220142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}