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
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.
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!
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;
}
getting following error now
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW)
thanks
Dear Vladimir,
Of course, sorry my mistake. Please replace "=>" with "=" in everything:
$query['date_query']['after']['year'] = date('Y');
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;
}
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.
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
for FTP is necessary to use Auth TLS connection on port 21. thanks
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?
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
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.
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.