Skip Navigation

[Resolved] Pagination not refect the actual number of records with filter

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 1 year, 9 months ago.

Assisted by: Luo Yang.

Author
Posts
#2557371
Screenshot 2023-02-19 at 6.17.41 PM.png
Screenshot 2023-02-19 at 6.17.30 PM.png

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?

#2557877

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

#2561299
Screenshot 2023-02-25 at 2.31.44 PM.png

Dear Luo,

How can I predefine the log-category as specific selection, like only show all error logs with failed in status field

#2562057

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';
    }
...