WordPress – URL Parameters on Custom Post Type Templates

I’m creating a plugin, that creates a custom post type called cars. I also created a template for it.

add_action( 'template_include', 'on_template_include' );
    public function on_template_include($original_template)
      global $wp;

      $custom_post_types = array($this->custom_post_name);

      if (in_array($wp->query_vars['post_type'], $custom_post_types))
        if (is_singular($this->custom_post_name))
          $original_template = plugin_dir_path(__FILE__).'template/single-car.php';
          $original_template = plugin_dir_path(__FILE__).'template/page-car.php';

      return $original_template;

Right now, when I enter
the page redirects to the page without problem.

What I want to do is, add a custom search to the page.

<div class="stock_search_form_wrapper">
  <div class="stock_search_form">
    <h3>Search Our Stock</h3>
    <form action="/cars/" method="get" id="searchform">
      <fieldset class="field-make">
        <label for="formfield_search_make">Make</label>
        <select class="csform" name="make" id="formfield_search_make">
        <option value="ABC">ABC</option>
        <option value="DEF">DEF</option>
      <fieldset class="submit">
        <input type="submit" id="formfield_search_submit" value="search">

When I submit page, I want it to redirect to the same page and I will change the query variables accordingly. The page goes to

But the page says ‘Object Not Found’. It doesn’t even go to 404 page. Template redirect code does not run either.

I figure I might need to add some rewrite code. I’ve found some codes and tried to change it but no success there either. Whatever I tried, the page says ‘Object Not Found’. (I updated permalinks.)

Thank you for your help,

Read more here: WordPress – URL Parameters on Custom Post Type Templates

Leave a Reply

Your email address will not be published. Required fields are marked *