Skip Navigation

[Resolved] filter posts of the last 3 months

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 7 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

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 2 replies, has 2 voices.

Last updated by nicolaT-2 7 years, 4 months ago.

Assisted by: Minesh.

Author
Posts
#546016

Hi,
I am trying to filter the posts published in the last 3 months. I set "date condition" in the view this way:

Select posts with => "published date", "after or equal to".
Year =>, I tried all of these: Constant (input field empty); CURRENT_ONE;
Month =>: PAST_ONE = 3.

I expected to see my last posts instead the view is showing nothing.

Reading other threads in the forum I saw Minesh suggested to set
Year => PAST_ONE = 1, but this way I'm getting also the posts of the past year, even if month was PAST_ONE = 3.
I tried even Year => PAST_ONE = 0 but this way I had no results.

This is the thread I watched: https://toolset.com/forums/topic/can-i-filter-a-view-by-posts-from-the-last-12-months/

How could be that difficult to filter my posts?

Thanks,
Nicola

#546075

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

As I understand you want exactly 90 days old posts from today's date. If that is correct - you need to add following code to your current theme's functios.php file.

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:
hidden link
https://toolset.com/documentation/user-guides/views-filters/wpv_filter_query/

#546185

Thank you Minesh.
Nicola

The forum ‘Types Community Support’ is closed to new topics and replies.