Skip Navigation

[Resolved] create filter to select events with date CF who define start and end date

This support ticket is created 2 years, 2 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 9 replies, has 2 voices.

Last updated by Minesh 2 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#2618735

I'm trying to create a query filter that shows a list of events from one date (start date >= now) up to another date (in between end date and start date), but something wrong.

I'm trying to modify this example:

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

add_filter( 'wpv_filter_query', 'filter_by_multiple_fields', 10, 3 );

function filter_by_multiple_fields( $query, $settings, $view_id ) {
if ( $view_id == 2004) {
$query['meta_query'] = array(
'relation' => 'OR',
array(
'key' => 'wpcf-data-dal',
'value' => '1',
'compare' => '=',
),
array(
'key' => 'wpcf-data-al',
'value' => '1',
'compare' => '=',
),
);
}
return $query;
}

Link to website test page hidden link

molte grazie

#2618849

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I would like to know that is date custom field created using Types plugin? If yes:
- What if your start date and what is your end date?

In addition to that:
Could you please send me debug information that will help us to investigate your issue.
=> https://toolset.com/faq/provide-debug-information-faster-support/

#2618869

I'm using Types and Toolset Views Legacy.
Field start date: wpcf-data-dal
Field end date: wpcf-data-dal

#2618881

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Thank you for sharing that information.

But what I would like to know is between what date range you want to search? Is there any specific date or you want to offer filter to users so whatever start and end date selected by user based on that you want to apply the search?

#2618901

I decide the interval the user cannot search. The scheme is as follows: the news is displayed in the front-end from the start date (wpcf-data-dal) and remains visible until the end date (wpcf-data-al)

#2618933

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Do you mean that out of all posts we will have to search form the smallest start date and biggest end date and then we should display all posts that falls between smallest start date and biggest end date?
OR
You mean you want to check current date against the start date and if the start date is grater than today's date and end date is less than today's date then you want to display the post?

#2619017

Posts must be visible from when they are published until the end date.
They must be visible even if the current date is less or equal to the start date

#2619049

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok so that solution would be you want to display the post until the post end date is less than the current date.

I'm thinking why you are adding the custom code.

What if you navigate to "Query Filter" section of your view and add the query filter for your end date custom field "wpcf-data-al" and
further select "number" and "lower than or equal " TODAY().

I hope this will help you to fix the issue, if it does not help, please send me admin access details and I'm happy to look at the issue further.

#2619183

if I use query filter for the end date custom field "wpcf-data-al" less or equal to" TODAY(), I show only the events before the end date and not the future events. I also want to display all events with start date in the future greater than or equal to TODAY()

#2619243

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

What if you navigate to "Query Filter" section of your view and:
- add the query filter for your end date custom field and further select "number" and "grater than or equal " TODAY().
- add the query filter for your start date custom field and further select "number" and "lower than or equal " TODAY().

I hope this will help you to fix the issue, if it does not help, please send me admin access details and I'm happy to look at the issue further.