Hi
I have a list of events and I'd like to filter these events by date. The date field comes from a custom field ([rhc_next_upcoming_dates]) ( hidden link ) which is not built with Toolset.
I have tried this but it doesn't work
add_filter('wpv_filter_query', 'add_custom_fields_to_view_query', 99, 3);
function add_custom_fields_to_view_query($query_args, $view_settings, $view_id ) {
if ( $view_id == 61 ){
return;
}
$meta_query = array();
$meta_query[] = array('key' => 'rhc_next_upcoming_dates');
return $query_args;
}
function custom_order($orderby) {
global $wpdb;
return $wpdb->postmeta.'.meta_value, mt1.meta_value, post_date ASC';
}
Regards
if ( $view_id == 61 ){
return;
}
This code basically says you want to apply the custom ordering filter to every View except View 61. Is that correct? If you only want to apply to view 61, then it should be this:
if ( $view_id != 61 ){
return;
}
$meta_query = array();
$meta_query[] = array('key' => 'rhc_next_upcoming_dates');
This code has nothing to do with Toolset, it's directly related to a WordPress Query using the 3rd-party custom field. If you need assistance, I suggest you reach out to the developers who created this rhc_next_upcoming_dates field to determine how to properly modify a WordPress Query to sort by their custom field value. Dates can be stored in many formats, so it's probably best to get their feedback. I'm glad to provide anything you need from Toolset to help facilitate this conversation. Our API's documentation for this filter is available here:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
Here's another ticket that includes a code sample for ordering by a custom numeric value. Your 3rd-party system may be able to use this example to help you formulate the correct query manipulations: https://toolset.com/forums/topic/sorting-by-custom-field/
This part is perfect, once you have made adjustments to the query in $query_args, you must return $query_args to the filter.
function custom_order($orderby) {
global $wpdb;
return $wpdb->postmeta.'.meta_value, mt1.meta_value, post_date ASC';
}
Not sure about this, again it's related to a 3rd-party system I don't know anything about.
My issue is resolved now. Thank you!