Skip Navigation

[Resolved] Restrict the view to the current day and past 30 days of the current year

This support ticket is created 2 years, 6 months ago. 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.

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

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 2 replies, has 2 voices.

Last updated by philipC-4 2 years, 6 months ago.

Assisted by: Shane.

Author
Posts
#2187009

Tell us what you are trying to do?

Hello, we would like to restrict the view to the current day and the past 30 days of the current year on "new listings". Can you please guide us on how to achieve this?

What is the link to your site?
hidden link

#2187147

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Philip,

Thank you for getting in touch.

The only way to do this is by using the view custom query filter to write a custom filter. Here is an example below.

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'  => '30 days ago',
        );
    }
    return $query_args;
}

Now what you need to do is to replace the 100 with the ID of the view that you want the code to apply to.

This code will display all the posts that were published in the last 30 days.

Thanks,
Shane

#2188005

My issue is resolved now. Thank you Shane!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.