title: How can I pass form input value inside PHP function properly in Wordpress?
body: <p>I'm trying to create a woocommerce custom filter, in which I can filter shop page by my custom meta keys, which already has been created.
  So I created a <code>form</code> before shop loop:</p>
  
  <pre><code>function _themename_woocommerce_custom_filter() {
      if( isset($_GET['submit']) ) {
          $year_min = esc_attr($_GET['year_min']);
          $year_max = esc_attr($_GET['year_max']);
      }
  
      ?&gt;
          &lt;form id="custom-filter" class="custom-filter" action="" method="get"&gt;
              &lt;input id="number_field_year_min" type="number" name="year_min" value="&lt;?php echo $year_min; ?&gt;" /&gt;
              &lt;input id="number_field_year_max" type="number" name="year_max" value="&lt;?php echo $year_max; ?&gt;" /&gt;
              &lt;input type="submit" name="submit" value="search"&gt;
          &lt;/form&gt;
      &lt;?php
  }
  add_action( 'woocommerce_before_shop_loop', '_themename_woocommerce_custom_filter', 3 );
  </code></pre>
  
  <p>So now I have two inputs and I want to get this values and pass inside this function, which is filtering my shop page product by meta key:</p>
  
  <pre><code>function show_only_products_with_specific_metakey( $meta_query, $query ) {
      $year_min = 1950;
      $year_max = 2020;
  
      if( ! is_shop() ) return $meta_query;
  
      $meta_query[] = array(
          'key'     =&gt; '_number_field_year',
          'value'   =&gt; array($year_min, $year_max),
          'compare' =&gt; 'BETWEEN'
      );
      return $meta_query;
  }
  add_filter( 'woocommerce_product_query_meta_query', 'show_only_products_with_specific_metakey', 10, 2 );
  </code></pre>
  
  <p>What I need is take my values from form after clicking submit button and pass it inside my function and change static values 1950 and 2020 to dynamic.</p>
  
  <p>Also I tried to use cookies like so:</p>
  
  <pre><code>$(document).ready(function () {
    const cookieMin = $("#number_field_year_min").val();
    createCookie("year_min_value", cookieMin, "10");
  });
  
  function createCookie(name, value, days) {
    var expires;
    if (days) {
      var date = new Date();
      date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
      expires = "; expires=" + date.toGMTString();
    }
    else {
      expires = "";
    }
    document.cookie = escape(name) + "=" + escape(value) + expires + "; path=/";
  }
  </code></pre>
  
  <p>and then pass it inside my function and change variable value:</p>
  
  <pre><code>$year_min = $_COOKIE['year_min_value'];
  </code></pre>
  
  <p>it's actually working, but only after second click on submit button and I'm not sure is it good practice to make like this.</p>
  
  <p>I tried my best to explain, sorry for my English. Thanks in advance!</p>