Skip Navigation

[Resuelto] Query filter – today to end of next week

This support ticket is created hace 9 años. 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
- 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 -
- - - - - - -

Supporter timezone: America/Sao_Paulo (GMT-03:00)

This topic contains 15 respuestas, has 2 mensajes.

Last updated by Adriano hace 9 años.

Assigned support staff: Adriano.

Autor
Mensajes
#220003

Hello,
is there a way how to filter post from today to end of next week. There are options for months but not for weeks.

Thank you for help
Vladimir

#220073

Dear Vladimir,

You will need to use the following code in functions.php in the current theme:

add_filter('wpv_filter_query', 'posts_end_next_week', 10, 2);
function posts_end_next_week($query, $settings) {
    if($settings['view_id'] = 123)
    {
        $nextWeek = strtotime('+2 Week');
        $query['year'] = date('Y', $nextWeek);
        $query['monthnum'] = date('m', $nextWeek);
        $query['day'] = date('d', $nextWeek);
    }
    return $query;
}

Please let me know if you are satisfied with my answer and if I can help you with any other question which is related with this one.

#220151

I have tried to apply it, changed the view_id to match my one, but it does not work.
No items found. would be possible to modify this function to use custom date field?

Thank you!

#220790

Dear Vladimir,

Yes, I think we can use a custom field for this, but first let me know how the code below goes:

add_filter('wpv_filter_query', 'posts_end_next_week', 10, 2);
function posts_end_next_week($query, $settings) {
    if($settings['view_id'] = 123)
    {
        $nextWeek = strtotime('+2 Week');

        $query['date_query']['after']['year'] => date('Y');
        $query['date_query']['after']['month'] => date('m');
        $query['date_query']['after']['day'] => date('d');

        $query['date_query']['before']['year'] => date('Y', $nextWeek);
        $query['date_query']['before']['month'] => date('m', $nextWeek);
        $query['date_query']['before']['day'] => date('d', $nextWeek);
    }
    return $query;
}
#220793

getting following error now
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW)

thanks

#220796

Dear Vladimir,

Of course, sorry my mistake. Please replace "=>" with "=" in everything:

$query['date_query']['after']['year'] = date('Y');

#220804

following code added, still no items found

add_filter('wpv_filter_query', 'posts_end_next_week', 10, 2);
function posts_end_next_week($query, $settings) {
    if($settings['view_id'] = 52)
    {
        $nextWeek = strtotime('+2 Week');
 
        $query['date_query']['after']['year'] = date('Y');
        $query['date_query']['after']['month'] = date('m');
        $query['date_query']['after']['day'] = date('d');
 
        $query['date_query']['before']['year'] = date('Y', $nextWeek);
        $query['date_query']['before']['month'] = date('m', $nextWeek);
        $query['date_query']['before']['day'] = date('d', $nextWeek);
    }
    return $query;
}
#220885

Dear Vladimir,

Could you share credentails of the site? I will test some codes on your site as soon as you provide it. The private area is enabled, you can share by there, please fill the required fields.

#220941

login information added. Its a wordpress test site, so don't worry about anything 🙂 view is added on this page hidden link site/?page_id=2 and custom taxonomy is called Denni nabidka.

Thanks

#220942

for FTP is necessary to use Auth TLS connection on port 21. thanks

#221126

Dear Vladimir,

Right, thank you for providing access. First I want to understand your issue better. You want to list posts between today and 2 weeks, right? You also want to use a custom date field to check this one, right? Want you to list posts with status scheduled (not published)? Is this field Datum?

#221360

I want to list between today and end of next week, so for example from 28/05/2014 - 8/6/2014
and I'd like to use custom field Datum. Published or scheduled does not matter, I was playing with the publishing date only for testing.
Thank you

#221633

Dear Vladimir,

My apologies the big delay, I was doing some tests to find the best solution for you. You can not use the custom field for this, you will need to use the date of the post. Because I will need to edit the filter in PHP using "wpv_filter_query" and it doesn't let me use custom fields.

So, the code below should works for you, you should put it in functions.php of the current theme:

add_filter('wpv_filter_query', 'show_only_today_func', 10, 2);
function show_only_today_func($query, $settings) {
    if($settings['view_id'] = 10)
    {
    	$nextWeek = strtotime('+1 Week');
    	$query['date_query']['before']['year'] = date('Y', $nextWeek);
        $query['date_query']['before']['month'] = date('m', $nextWeek);
        $query['date_query']['before']['day'] = date('d', $nextWeek);

        $query['post_status'] = array('publish', 'draft', 'private', 'scheduled');
        return $query;
    }
}

You must replace 10 with the ID of your view.

Please let me know if you are satisfied with my answer and if I can help you with any other related question.

#221635
views_filter.png

Dear Vladimir,

Sorry, I forgot to tell you that will be needed a Views filter for this. See the attached image, it is the one.

#222184

Thank you for help 🙂