Title: Searching by date range
Last modified: August 30, 2016

---

# Searching by date range

 *  Resolved [titodevera](https://wordpress.org/support/users/titodevera/)
 * (@titodevera)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/searching-by-date-range/)
 * Hello. I´m trying to search by date range but it´s not working. Here is my code:
 *     ```
       add_filter('uwpqsf_query_args','insert_date_to_query','',3);
           //if you are using default template, you will need to replace uwpqsf_query_args with uwpqsf_deftemp_query instead
           function insert_date_to_query($args,$id,$getdata){
                $args['date_query'] = array(
                       'after'     => strtotime($getdata['date']['from']),
                       'before'    =>  strtotime($getdata['date']['to']),
                       'inclusive' => true
                 );
   
             return $args;
           }
   
           add_action('uwpqsf_form_bottom','insert_date_input');
           function insert_date_input($attr){
                 $html = '<div class="uwpqsf_class">';
                 $html .= '<div><label><span>Desde <small>(fecha)</small></span> <input name="date[from]" value="" type="text" class="datep"></label></div>';//you can use select or other input type
                 $html .='</div>';
                 $html .= '<div class="uwpqsf_class">';
                 $html .= '<div><label> <span>Hasta <small>(fecha)</small></span> <input name="date[to]" value="" type="text" class="datep"></label></div>';
                 $html .='</div>';
                 echo $html;
           }
       ```
   
 * It seems like filter “uwpqsf_query_args” is not working.
 * Thanks a lot!!
 * [https://wordpress.org/plugins/ultimate-wp-query-search-filter/](https://wordpress.org/plugins/ultimate-wp-query-search-filter/)

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Author [TC.K](https://wordpress.org/support/users/wp_dummy/)
 * (@wp_dummy)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/searching-by-date-range/#post-6787768)
 * `uwpqsf_query_args` is for ajax result,if you are using default search template
   than you should use `uwpqsf_deftemp_query` instead.
 *  Thread Starter [titodevera](https://wordpress.org/support/users/titodevera/)
 * (@titodevera)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/searching-by-date-range/#post-6787935)
 * Perfect, it´s working now, thank you so much 🙂
 * Here´s my code (maybe help someone):
 *     ```
       add_filter('uwpqsf_deftemp_query','insert_date_to_query','',3);
       function insert_date_to_query($args,$id,$getdata){
   
           $fromArray = explode("/",$getdata['date']['from']);
           $toArray = explode("/",$getdata['date']['to']);
   
           if(sizeof($fromArray) == 3 && sizeof($toArray) == 3){
               $args['date_query'] = array(
                   'after'     => array(
                       'year' => $fromArray[2],
                       'month' => $fromArray[1],
                       'day' => $fromArray[0]
                   ),
                   'before'    =>  array(
                       'year' => $toArray[2],
                       'month' => $toArray[1],
                       'day' => $toArray[0]
                   ),
                   'inclusive' => true
               );
           }
           return $args;
       }
       ```
   
 *  [mojamba](https://wordpress.org/support/users/mojamba/)
 * (@mojamba)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/searching-by-date-range/#post-6787943)
 * For anyone else finding this, there is another, earlier thread on the same topic
   which includes my code on adding a robust jQuery datepicker. See: [https://wordpress.org/support/topic/search-by-a-date-range?replies=14](https://wordpress.org/support/topic/search-by-a-date-range?replies=14)
 *  [Pete](https://wordpress.org/support/users/perthmetro/)
 * (@perthmetro)
 * [10 years ago](https://wordpress.org/support/topic/searching-by-date-range/#post-6787995)
 * I’m having trouble following the thread with the jQuery datepicker. Would you
   mind showing the final code we need here, thanks.
 *  [mojamba](https://wordpress.org/support/users/mojamba/)
 * (@mojamba)
 * [10 years ago](https://wordpress.org/support/topic/searching-by-date-range/#post-6787996)
 * perthmetro, it would help if you were more specific. Are you referring to this
   thread or the one I linked to (that actually discusses a jQuery datepicker). 
   In either case, both threads show code to use so I am not sure what you are asking
   for.
 *  [mrspabs](https://wordpress.org/support/users/mrspabs/)
 * (@mrspabs)
 * [8 years, 12 months ago](https://wordpress.org/support/topic/searching-by-date-range/#post-9157883)
 * Thank you for this code, here is my adaptation of it!
 *     ```
       add_action('uwpqsf_form_bottom','insert_date_input');
       function insert_date_input($attr){
       		$html = '<div class="uwpqsf_class"><span class="taxolabel-2">Date Range</span>';
       		$html .= '<div><label><span style="display:block;">From </span> <select class="monthsearch" name="date[from-month]">   <option value="">--Select Month--</option><option  value="1">Janaury</option><option value="2">February</option><option value="3">March</option><option value="4">April</option><option value="5">May</option><option value="6">June</option><option value="7">July</option><option value="8">August</option><option value="9">September</option><option value="10">October</option><option value="11">November</option><option value="12">December</option></select>  <input name="date[from-year]" size="4" value="" class="yearsearch" type="text" placeholder="YYYY"></label></div>';//you can use select or other input type
       		$html .='</div>';
       		$html .= '<div class="uwpqsf_class">';
       		$html .= '<div><label> <span style="display:block;">To </span> <select class="monthsearch" name="date[to-month]">   <option value="">--Select Month--</option><option  value="1">Janaury</option><option value="2">February</option><option value="3">March</option><option value="4">April</option><option value="5">May</option><option value="6">June</option><option value="7">July</option><option value="8">August</option><option value="9">September</option><option value="10">October</option><option value="11">November</option><option value="12">December</option></select> <input name="date[to-year]" value="" class="yearsearch" type="text" placeholder="YYYY"></label></div>';
       		$html .='</div>';
       		echo $html;
       }
   
       add_filter('uwpqsf_deftemp_query','insert_date_to_query','',3);
       function insert_date_to_query($args,$id,$getdata){
   
       	 $args['date_query'] = array(
       		  'after'     => array(
       				'year' => $getdata['date']['from-year'],
       				'month' => $getdata['date']['from-month'],
       				'day' => '1'
       		  ),
       		  'before'    =>  array(
       				'year' => $getdata['date']['to-year'],
       				'month' => $getdata['date']['to-month'],
       				'day' => '31'
       		  ),
       		  'inclusive' => true
       	 );
   
       return $args;
       }
       ```
   
 * ![Filters](https://i0.wp.com/i63.tinypic.com/2pzb1hf.jpg)
 * how do i get it to show what the user searched for in the search results. is 
   there is way to get the “value” and “selected” to update on the search result
   page?
    -  This reply was modified 8 years, 12 months ago by [mrspabs](https://wordpress.org/support/users/mrspabs/).

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Searching by date range’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/ultimate-wp-query-search-filter_fcfcfc.
   svg)
 * [Ultimate WP Query Search Filter](https://wordpress.org/plugins/ultimate-wp-query-search-filter/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ultimate-wp-query-search-filter/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ultimate-wp-query-search-filter/)
 * [Active Topics](https://wordpress.org/support/plugin/ultimate-wp-query-search-filter/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ultimate-wp-query-search-filter/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ultimate-wp-query-search-filter/reviews/)

## Tags

 * [date range](https://wordpress.org/support/topic-tag/date-range/)

 * 6 replies
 * 5 participants
 * Last reply from: [mrspabs](https://wordpress.org/support/users/mrspabs/)
 * Last activity: [8 years, 12 months ago](https://wordpress.org/support/topic/searching-by-date-range/#post-9157883)
 * Status: resolved