Skip Navigation

[Resolved] Date filtering not working as expected

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
- 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)

This topic contains 4 replies, has 2 voices.

Last updated by simonM-5 1 year, 6 months ago.

Assisted by: Minesh.

Author
Posts
#2618087
Screenshot 2023-06-22 at 21.50.00.png
Screenshot 2023-06-22 at 21.45.11.png
Screenshot 2023-06-22 at 21.46.34.png

Hi Support

I am trying to:
Filter a Toolset View "Find a Native Nanny Guest Search and Results View" to show only posts created in the last 185 days. I have tried several queries with varying results.
1) Tried Published date between Day CURRENT_ONE and PAST_ONE = 185 (0 results)
2) Tried after or equal to Day PAST_ONE = 185 (4 results)
3) Tried after or equal to Month PAST_ONE = 6 (0 results)

Link to a page where the issue can be seen:
hidden link

I expected to see:
7 posts

Instead, I got:
4 or zero posts

Am I missing the point somehow, or is the filtering really not working?

Kind regards
Simon

#2618327

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

I've added the following code to "Custom Code" section offered by Toolset with the newly added code snippet namely "nanny-guest-search-post-date-filter":
=> hidden link

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'] == 24671) {
        $query_args['date_query'] = array(
            'column' => 'post_date',
            'after'  => '185 days ago',
        );
    }
    return $query_args;
}

I can see now correct result that is 7 on frontend:
=> hidden link

Can you please confirm it works as expected.

#2618339

HI Minesh

1) So, because you are providing custom code, is that a confirmation that this is a bug? Will this be addressed in a plugin update?

2) We would like to use the same logic on 4 views:

ID View
24721 Find a Job Guest Search and Results View
2231 Find a Job Search and Results View
24671 Find a Native Nanny Guest Search and Results View
2145 Find a Native Nanny Search and Results View

Would you be so kind as to adjust the code accordingly, so we can use just one custom snippet rather than 4 different ones?

Thank you and kind regards
Simon

#2618361

Minesh
Supporter

Languages: English (English )

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

1) So, because you are providing custom code, is that a confirmation that this is a bug? Will this be addressed in a plugin update?
==>
No - its not a bug but if you use the "Query Filter" you will require to add specific year as well.

2) We would like to use the same logic on 4 views:
==>
I've adjusted the code as given under:

add_filter( 'wpv_filter_query', 'get_past_posts_number_of_days_ago', 10, 3);
function get_past_posts_number_of_days_ago( $query_args ,$view_settings,$view_id) {
    $allowed_ids = array(24721,2231,24671,2145);
    if (in_array($view_id,$allowed_ids)) {
        $query_args['date_query'] = array(
            'column' => 'post_date',
            'after'  => '185 days ago',
        );
    }
    return $query_args;
}
#2619157

Thanks Minesh. That does the trick! 🙂

My issue is resolved now. Thank you!