title: Custom, separate search form and search results page in Wordpress
body: <p><strong>Goal/Information</strong></p>
  
  <p>I'm trying to set up a custom search field and custom search results page to display one category of pages. I need these results on a separate, custom search results page so I can customize how the results are displayed without affecting the default search.</p>
  
  <p>For context, I'm setting up a gallery where the user can search for keywords and relevant pages will be displayed as a thumbnail grid, with each thumbnail linking to a page containing more information on the image.</p>
  
  <p>Each page, containing the image and information, is set up as a page (not post) under the category <code>images</code>.</p>
  
  <p>I'm not sure this is relevant, but in a previous project I've set the default search to exclude <code>images</code> pages with the following code in my functions.php (category ID is 30). I've tried removing this code and it didn't affect my problem described below.</p>
  
  <pre><code>/* Exclude a Category from Search Results */
  add_filter( 'pre_get_posts' , 'search_exc_cats' );
  function search_exc_cats( $query ) {
      if( $query-&gt;is_admin )
          return $query;
      if( $query-&gt;is_search ) {
          $query-&gt;set( 'category__not_in' , array( 30 ) ); // Cat ID
      }
      return $query;
  }
  </code></pre>
  
  <p><strong>What I've Tried</strong></p>
  
  <p>I'm still learning php and have spent many hours on this to no avail. Most recently I tried tweaking some code from <a href="https://stackoverflow.com/questions/37145303/wordpress-custom-post-type-search-results-page">this similar question</a>.</p>
  
  <p>My resultant custom search form looks like this:</p>
  
  <pre><code>&lt;form class="search-form" action="&lt;?php echo home_url( '/' ); ?&gt;" method="get"&gt;
    &lt;input name="s" type="text" placeholder="Search Images" /&gt;
    &lt;input name="post_type" type="hidden" value="page" /&gt;
    &lt;input name="category_name" type="hidden" value="images" /&gt;
    &lt;input alt="Search" type="submit" value="Search" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I've added the following code to the top of my search.php to attempt to redirect to another results page, in this case search-page.php, if the post type has been specified:</p>
  
  <pre><code>&lt;?php
  // store the post type from the URL string
  $post_type = $_GET['post_type'];
  // check to see if there was a post type in the
  // URL string and if a results template for that
  // post type actually exists
  if ( isset( $post_type ) &amp;&amp; locate_template( 'search-' . $post_type . '.php' ) ) {
      // if so, load that template
      get_template_part( 'search', $post_type );
  
      // and then exit out
      exit;
  }
  ?&gt;
  </code></pre>
  
  <p><em>Note: I took this directly from the similar question linked above.</em></p>
  
  <p>I've duplicated search.php into search-page.php, removing the code above from the latter.</p>
  
  <p><strong>Problem</strong></p>
  
  <p>Now let's do a search in the custom form above for "marble" (a term featured in one of the <code>image</code> pages). The URL looks right (<code>http://example.com/%3C?s=marble&amp;post_type=page&amp;category_name=images</code>), but I get a 404. In addition, normal searches (those not in the custom form) now take me to a white page – not even a 404. When I remove the above code from functions.php, the default search works properly. (Custom search still 404s.)</p>
  
  <p><strong>Other Attempts</strong></p>
  
  <p>I've also read this guide from Smashing Magazine a few times – <a href="https://www.smashingmagazine.com/2016/03/advanced-wordpress-search-with-wp_query/" rel="nofollow noreferrer">Building An Advanced WordPress Search With WP_Query</a> – but can't quite pick out the information relevant to me. </p>
  
  <p>I've tried a couple dozen other guides and questions, but most of them deal with searching for a specific post type alone (and not a category) or searching from a radio-button selection of categories. I haven't been able to scrape any working solutions from them.</p>
  
  <p>Are there any tweaks to what I've tried – or completely different solutions altogether – that will help achieve the desired effect? Specifically, <strong>how to create a custom search form for one type of page category, leading to a customizable, separate search results page (independent from the default search results page).</strong></p>
  
  <p>Thanks in advance.</p>