Passer la navigation

[Résolu] Restrict the view to the current day and past 30 days of the current year

This support ticket is created Il y a 4 years, 8 months. 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 -

Fuseau horaire du supporter : America/Jamaica (GMT-05:00)

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par philipC-4 Il y a 4 years, 8 months.

Assisté par: Shane.

Auteur
Publications
#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?
lien caché

#2187147

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: 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!