There is a wordpress filter on the site page that displays data depending on age on the same page.

I give the full code of the filter:

 <form action="" method="post"> <label class="ages">Введите возраст: <input type="number" name="age"/> </label> <button type="submit">Найти</button> </form> <div> <?php $args = array ( 'post_type' => 'method', 'posts_per_page' => '-1', 'relation' => 'AND', 'meta_query' => array( 'key' => 'age_min', 'value' => (int) $_POST["age"], 'type' => 'numeric', 'compare' => '<=' ), ); $the_query = new WP_Query( $args ); while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <div class="name"><?php the_title(); ?></div> <?php endwhile; wp_reset_postdata(); ?> </div> 

How to do so, when clicking a button on the <button>Очистить результат</button> , the results were reset and returned to the initial position like:

 if (isset($_POST['age'])) { unset($_POST['age'])); } 

UPD: there is a solution, but it is incomplete - you need to send the same form with an empty value

 <form action="" method="post"> <button type="submit" name="age" value="">Очистить результат</button> </form> 

, but there is a nuance: $_POST['age'] can be set to 0 , and value="" is equated to it and now the filter is triggered by zero

  • with your turnip is a sin to ask)) what does it do where? Aayaks, net html / pkhp? - Jean-Claude
  • @ Jean-Claude is clean. Well, I'm stupid somewhere, it does not work. I thought something like that will roll <input type="button" value="Очистить результат" onclick="getElementsByName('age')[0].value = ''"> but no .. - Vasya
  • @ Vasya, and what <input type = "reset"> does not fit? - Nsk 5:59
  • document.querySelector ('input [name = "age"]'). value = ''; - Victor Pupkin Nov.
  • @Nsk explain. Do you mean cleaning before submitting the form? But, I need to change the value of $_POST['age'] after sending - Vasya

0