Plugin Author
TC.K
(@wp_dummy)
uwpqsf_query_args
is for ajax result,if you are using default search template than you should use uwpqsf_deftemp_query
instead.
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;
}
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
I’m having trouble following the thread with the jQuery datepicker. Would you mind showing the final code we need here, thanks.
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.
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;
}
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 6 years, 11 months ago by mrspabs.