Skip Navigation

[Resolved] Create a post date filter to find items published within the last 10 minutes

This support ticket is created 4 years, 5 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Bobby339 4 years, 5 months ago.

Assisted by: Nigel.

Author
Posts
#1389117
filter.jpg

As the title says, I am trying to create a filter that will find posts published between right now and 10 minutes ago but it's not working 🙁

I'm uploading a screenshot of my filter, can you tell me where I am going wrong?

#1389127

also... how does it work with the hour changing and/or the day changing? If it's really complex, don't worry about it.

#1389243

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Bobby

Those settings for filtering post published date are tricky and in my experience it's not possible to set up such a filter for "since" type queries such as since 10 minutes ago.

It is easier to just use the Views API and add a date_query argument, which accepts a very flexible textual comparison.

Try the following, after editing the ID of your View.

function tssupp_filter_query($view_args, $view_settings, $view_id)
{
    if (in_array($view_id, array(123))) { // Edit 123 for your View ID
 
        $view_args['date_query'] = array(
            'after'     =>  '10 minutes ago',
            'column'    =>  'post_modified'
        );
    }
    return $view_args;
}
add_filter('wpv_filter_query', 'tssupp_filter_query', 101, 3);
#1390295

My issue is resolved now. Thank you!

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