Skip Navigation

[Résolu] Filter posts by custom date field greater than equal to today

This support ticket is created Il y a 6 années et 8 mois. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Marqué : ,

This topic contains 3 réponses, has 2 voix.

Last updated by Noman Il y a 6 années et 8 mois.

Assisted by: Noman.

Auteur
Publications
#555029

Tell us what you are trying to do?

I have a parametric search filter which filters events and activities custom post types with Start Date and End Date custom fields (created by types)
hidden link

I want that the view by default shows only upcoming events, i.e. where End Date is equal to or greater than today.

I have been trying to use wpv_filter_query but I guess i'm missing something.

Your help will be highly appreciated.

add_filter( 'wpv_filter_query', 'upcoming_events_gt_today', 999, 3 );
   
function upcoming_events_gt_today( $query_args, $view_settings, $view_id ) {
    if (in_array($view_id, array(53165) ) ) {
    	 $today_date = date();
         $query_args["meta_key"] =  "wpcf-event-end-date-and-time" ;
         $query_args["meta_value"] =  $today ;
    	 $query_args["meta_type"] = "numeric"; // Importan
    	 $query_args["meta_compare"] = ">="; // Importan
    }
    return $query_args;
}
#555102

Noman
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Shreyas,

Thank you for contacting Toolset support. Please use the following updated code and let me know how it goes:

add_filter( 'wpv_filter_query', 'upcoming_events_gt_today', 999, 3 );
    
function upcoming_events_gt_today( $query_args, $view_settings, $view_id ) {
    if (in_array($view_id, array(53165) ) ) {
         $today_date = date_i18n('Y/m/d');
         $query_args["meta_key"] =  "wpcf-event-end-date-and-time" ;
         $query_args["meta_value"] =  $today_date ;
         $query_args["meta_type"] = "numeric"; // Importan
         $query_args["meta_compare"] = ">="; // Importan
    }
    return $query_args;
}

Thank you

#555209

Dear Noman,

This does not work. I've also tried to change the priority.

add_filter( 'wpv_filter_query', 'upcoming_events_gt_today', 99, 3 );
     
function upcoming_events_gt_today( $query_args, $view_settings, $view_id ) {
    if (in_array($view_id, array(53165) ) ) {
         $today_date = date_i18n('Y/m/d');
         $query_args["meta_key"] =  "wpcf-event-end-date-and-time" ;
         $query_args["meta_value"] =  $today_date ;
         $query_args["meta_type"] = "numeric"; // Important
         $query_args["meta_compare"] = ">="; // Important
    }
    return $query_args;
}
#555264

Noman
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello,

The code is working fine at my end. To further debug this issue I need to take a look at your setup and to request temporary website WP-admin and FTP info for your site to debug further and to help in resolving this. Your next answer will be private which means only you and I have access to it.

=== Please backup your database and website ===

✙ I would additionally need your permission to de-activate and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important.

✙ Please add the Link to the [View] Edit Screen. Thank you

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