OK.
The basic concept here is we add two hidden fields (for sorting and post per page) in the search form, and add use the js to fill the value when user make changes in the sorting and post per page input fields.
Since you are not using the pagination, you can remove the entire line:
echo $apiclass->ajax_pagination($arg['paged'],$query->max_num_pages, 4, $id, $getdata);
And you can replace with the sorting and page per page option:
echo "<div id="custompagi">";
echo "<select data-from=".$id." class="sort" name="sorting">";
echo "<option value="desc">Descending</option>";
echo "<option value="asc">Ascending</option>";
echo "</select>";
//result per page
echo "<select data-from=".$id." class="perpage" name="perpage">";
echo "<option value="10">10</option>";
echo "<option value="20">20</option>";
echo "<option value="30">30</option>";
echo "</select>";
echo "</div>"
Note that added the data-form
for the form id and div wrapper. It will be used later in js selector.
Then in the search form add 2 hidden field for corresponding field above.
add_action("uwpqsf_form_bottom", "add_custom_field");
function add_custom_field($atts){
echo '<input type="hidden" class="sorting" name="sorting">';
echo '<input type="hidden" class="postperpage" name="perpage">';
}
Then take those hidden in the query:
add_filter("uwpqsf_query_args", "add_custom_input","",3);
function add_custom_input($args, $id,$getdata){
//we only take the sorting and per page value when it is not empty
if(isset($getdata['sorting']) && !empty($getdata['sorting'])){
$args["order"] = $getdata["sorting"];
}
if(isset($getdata['perpage']) && !empty($getdata['perpage'])){
$args["posts_per_page"] = $getdata["perpage"];
}
return $args;
}
That’s all for the php part. Now we goes to js part:
So, add a js script in the template, I assumed you already know how to do it.
In the js script:
for sorting:
$("#custompagi").on("change", '.sort', function(e){
var currentval = $(this).val();
//form id for current search
var formID = $(this).attr('data-form');
var formSelector = '#uwpqsffrom_' + formID;
//set the corresponding hidden value
$(''+formSelector+'').find(".sorting").val(currentval);
//then submit the form
$(''+formSelector+'').submit();
});
Note that it must use .on() for bind the change event, because it is ajax generated dom. Otherwise it won’t work.
And you can repeat above code for post per page.
Note that the codes is not tested, it is only for references. I hope you can understand the concept of the integration.