title: Destroy a session with ajax to avoid exiting page
body: <p>When a user visits a search result page, the user needs to click "clear search filters" which redirects the user to the search page. The session is cleared upon this action.</p>
  
  <p>I'm looking for a way to destroy the session via ajax - so that the user can make use of the filter options directly on the search results page (without having to go back to the search page).</p>
  
  <p>This the code I have now:</p>
  
  <pre><code>&lt;?php session_start(); if($_GET['action']=='reset') {
    session_destroy();
    wp_redirect( 'http://website.com/search' ); exit;  
  } else { 
    if(!is_page(4097))  { 
    session_destroy(); } 
  } ?&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html &lt;?php language_attributes(); ?&gt;&gt;
  &lt;head&gt;
  &lt;/head&gt;
  
  
  &lt;body&gt;
  &lt;?php if(!is_page(4097)) { ?&gt;
  &lt;form name="search-form" method="post" action="&lt;?php echo get_permalink(4097);?&gt;"&gt;
      &lt;select name="one"&gt;
         &lt;?php echo $form_options_one; ?&gt;
      &lt;/select&gt;
      &lt;select name="two"&gt;
         &lt;?php echo $form_options_two; ?&gt;
      &lt;/select&gt;
      &lt;input type="submit" name="submit" value="Search"&gt;
  &lt;/form&gt;
  &lt;?php }?&gt;
  
  &lt;div id="container"&gt;
  </code></pre>
  
  <p>search_and_results.php code is below:</p>
  
  <pre><code>&lt;?php 
  session_start();
  get_header();
  if($_GET['action']=='reset'){
  session_destroy();
  wp_redirect( get_permalink(get_the_ID()) ); exit; 
  }?&gt;
  
      &lt;div id="content"&gt;  
  
              &lt;?php if(!isset($_POST['submit']) &amp;&amp; (!isset($_SESSION['one'])) &amp;&amp; (!isset($_SESSION['two']))) { ?&gt;
              &lt;form name="search-form" method="post" action="&lt;?php echo get_permalink(4097);?&gt;"&gt;
                  &lt;select name="one"&gt;
                     &lt;?php echo $form_options_one; ?&gt;
                  &lt;/select&gt;
                  &lt;select name="two"&gt;
                     &lt;?php echo $form_options_two; ?&gt;
                  &lt;/select&gt;
                  &lt;input type="submit" name="submit" value="Search"&gt;
              &lt;/form&gt;
  
  
              &lt;?php } else {          
                  $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
                  $the_query = new WP_Query($args); ?&gt;
                  &lt;?php if ( $the_query-&gt;have_posts() ) : ?&gt;
                    &lt;!-- the loop --&gt;
                    &lt;?php while ( $the_query-&gt;have_posts() ) : $the_query-&gt;the_post(); ?&gt;
                      &lt;?php $author_data= get_userdata($post-&gt;post_author); $author_meta= get_user_meta($post-&gt;post_author); ?&gt;
                      &lt;?php if(($author_data-&gt;roles[0]=='editor') || ($author_data-&gt;roles[0]=='contributor') || ($author_data-&gt;roles[0]=='subscriber') ) { ?&gt;
                      // only get posts from editors, contributors, and subscribers
  
                              &lt;!--post stuff here--&gt;
  
                      &lt;?php }?&gt;           
                    &lt;?php endwhile; ?&gt; &lt;!-- end of the loop --&gt;
  
                    &lt;!-- pagination here --&gt;
                  &lt;?php if($the_query-&gt;max_num_pages==1) {
                      session_destroy();
                  }?&gt;
  
                  &lt;?php  if ( $the_query-&gt;max_num_pages &gt; 1 ) : ?&gt;
  
                  &lt;div class="main_navigation"&gt;
                      &lt;?php
                      // usage with max_num_pages
                      next_posts_link( 'Next Page &amp;raquo;', $the_query-&gt;max_num_pages );
                      previous_posts_link( '&amp;laquo; Previous Page' );
                      ?&gt;
                  &lt;/div&gt;
  
                  &lt;?php endif; ?&gt;
  
                    &lt;?php wp_reset_postdata(); ?&gt;
  
                  &lt;?php else:  ?&gt;
                    &lt;p&gt;&lt;?php _e( 'Sorry, no posts matched your criteria.' ); ?&gt;&lt;/p&gt;
                  &lt;?php endif; ?&gt;
  
  
              &lt;div class="back-to-form clearfix"&gt;
                  &lt;a href="&lt;?php echo home_url('/') ?&gt;?action=reset" class="clear_filter button"&gt;&lt; Clear search filters&lt;/a&gt;
              &lt;/div&gt;
                  &lt;?php  } ?&gt;
  
  &lt;/div&gt;&lt;!-- end content id --&gt;
   &lt;/div&gt;&lt;!--container--&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Is this possible given the structure above? Thanks so much</p>