Dear Sir/Madam,
I have the predefined filters when customer visit my View, below is the filter control
[wpv-filter-controls]
<div class="row filter-div">
<div class="col col-lg-3 col-xs-12">
[wpv-control-post-taxonomy taxonomy="log-category" type="checkboxes" url_param="wpv-log-category"]
</div>
<div class="col col-lg-3 col-xs-12">
[wpv-control-postmeta field="wpcf-log-status" type="checkboxes" source="custom" url_param="wpv-wpcf-log-status" values="failed,success" display_values="失敗,成功" class="log-status"]
</div>
<div class="col col-lg-4 col-xs-12">
<label for="wpv-wpcf-log-timestamp_min">[wpml-string context="wpv-views"]由[/wpml-string]</label>
[wpv-control-postmeta type="date" field="wpcf-log-timestamp" date_format="d-M-Y" default_date="today()" url_param="wpv-wpcf-log-timestamp_min"]
<label for="wpv-wpcf-log-timestamp_max">[wpml-string context="wpv-views"]至[/wpml-string]</label>
[wpv-control-postmeta type="date" field="wpcf-log-timestamp" date_format="d-M-Y" url_param="wpv-wpcf-log-timestamp_max"]
</div>
<div class="col col-lg-2 col-xs-12">
[wpv-filter-reset]
</div>
</div>
[/wpv-filter-controls]
My predefined filter, including the default_date=today(), refer to the screenshot, you should able to see the pagination are same no matter I have the default date or not. I assume the pagination result should be calculated after the filter, how can I fix it.
By the way, how can I pre-checked the log-cateogry?
Hello,
You can use filter hook wpv_filter_query to setup the default filter value, and filter the results.
For example:
add_filter('wpv_filter_query', function($query, $settings, $view_id){
if($view_id == 123 && !isset($_GET['wpv-wpcf-log-timestamp_min'])){
$_GET['wpv-wpcf-log-timestamp_min'] = strtotime('today');
}
return $query;
}, 1, 3);
Please replace 123 with your post view's ID
More help:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
Dear Luo,
How can I predefine the log-category as specific selection, like only show all error logs with failed in status field
Similar as above, you can add below codes in that custom PHP function, like this:
...
if($view_id == 123 && !isset($_GET['wpv-log-category'])){
$_GET['wpv-wpcf-log-timestamp_min'] = 'fail';
}
...