Skip Navigation

[Gelöst] Problems With Filtering Views Query by Date

This support ticket is created vor 7 Jahren, 1 Monat. There's a good chance that you are reading advice that it now obsolete.

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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

Dieses Thema enthält 8 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Boris vor 7 Jahren.

Assistiert von: Minesh.

Author
Artikel
#577284
123.jpg

Hello,

I am trying to filter 3 views queries as described:

1. Display posts published recent day
2. Display posts published between recent 2-7 days.
3. Display posts published between recent 8-30 days.

I tried a lot of combinations but the results are not correct.

Any advice will be appreciated.

Thanks

#577336

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - first of all, after checking debug information you shared with us I found that you are running with outdated Toolset plugins.

*** Please make a FULL BACKUP of your database and website.***
Could you please update ALL Toolset plugins to it's latest official release version. You can download latest Toolset plugins from:
=> https://toolset.com/account/downloads/

We have detailed Doc which may help you how you can filter your posts by publish date:
=> https://toolset.com/documentation/user-guides/filtering-views-query-by-date/

If above does not help much and dont give you full flexibility then you should use view's filter wpv_filter_query:
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

For example:

add_filter( 'wpv_filter_query', 'get_past_one_month_posts', 10, 2);
function get_past_one_month_posts( $query_args ,$view_settings ) {
 
    if (isset($view_settings['view_id']) && $view_settings['view_id'] == 100) {
        $query_args['date_query'] = array(
            'column' => 'post_date',
            'after'  => '90 days ago',
        );
    }
    return $query_args;
}

Where:
replace '100' with your original view ID.

More info:
=> versteckter Link

#578176

Hello

I have updated WoprdPress and Toolset plugins.

I have replaced '100' with my original view ID.

However, the problem still exists, showing incorrect results.

Thanks

#578185

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

Could you please share problem URL.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#578201

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

Well - I've added the following code to display 1 day old posts to your theme's functions.php file.

add_filter( 'wpv_filter_query', 'limit_query_one_day', 10, 3 );

function limit_query_one_day($query_args, $view_setting, $view_id){

 if ($view_id == 5439){

  $query_args['date_query'] = array(

   array(

    'after' => '1 day ago'

   )

      );

 }

    return $query_args;

}

You can adjust number of days with above code accordingly.

For test purpose I've set the promoted custom field value for the following post. This post created today:
=> versteckter Link

Now, I can see that above post is displayed on frontend..

#578211

Great.

I have set the query to display posts of recent 2 days:

add_filter( 'wpv_filter_query', 'limit_query_one_day', 10, 3 );
function limit_query_one_day($query_args, $view_setting, $view_id){
 if ($view_id == 5439){
  $query_args['date_query'] = array(
   array(
    'after' => '2 day ago'
   )
      );
 }
    return $query_args;
}

1. How can I Skip first 5 items ?

2. How can I view posts posted in the time period 3-7 days ago?

Thank you for your time.

#578219

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

1. How can I Skip first 5 items ?
=> Well - to skip the first 5 items, we have setting available on views page. Please check the following image:
versteckter Link

2. How can I view posts posted in the time period 3-7 days ago?
=> That means you want to dispaly only 4 days old post in range 3-7. I've modified your view's filter as given under:

add_filter( 'wpv_filter_query', 'limit_query_one_day', 10, 3 );
function limit_query_one_day($query_args, $view_setting, $view_id){
 if ($view_id == 5439){
  $query_args['date_query'] = array(
   array(
   'before' => '3 day ago',
    'after' => '7 day ago',
	
   )
      );
 }
    return $query_args;
}

You can adjust days values according to your requirement.

#578434

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

Could you please confirm the solutions I shared with you is working for you.

#579306

It looks good!

Thanks.