I have a view that displays two cpts Containers and Shipments, and it has a custom parent relationship filter that Minesh helped me with here (https://toolset.com/forums/topic/filter-view-by-parent-post/). I am now attempting to add a date search that combines two custom date fields, Container Confirmation Date and Shipment Confirmation Date.
I'm running into two issues now. First if I input a date (I've tried with text and datepicker inputs) but do not select a warehouse (parent filter mentioned above) I get a blank page. Second, if I select a warehouse, I get results but it doesn't apply the date filter.
I thought this may have something to do with only being able to use the AND operator within the view, so I found the fix for that here (https://toolset.com/errata/and-always-used-with-multiple-views-query-filters-even-if-or-is-specified/), unfortunately that causes a critical error on the site. I reformatted it a bit and removed the array in favor of a single view id and it has no affect. Thought it would be good to mention.
I'll provide access to the site and further info in my follow-up.
Hello. Thank you for contacting the Toolset support.
Could you please share admin access details and problem URL and exact steps I will have to follow to see both the issues.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
I can see that you have added the custom field filter as date filter for the custom field "wpv-conf-date" - do you mean that you want to match the fields Container Confirmation Date and Shipment Confirmation Date equal to selected conf-date?
Unfortunately it doesn't appear to be working. I tested by selecting the date April 15th 2023 and it is still returning posts with dates prior to that as seen in the screenshot. I tested both with and without assigning a warehouse filter, same results.
I see why its not working could be because I see there is another filter added that applies OR condition for all the custom field query.
add_filter( 'wpv_filter_query', 'wpv_filter_query_func', 1000 , 3 );
function wpv_filter_query_func( $query_args, $view_settings ) {
// process if specific view
if ( ( isset($view_settings['view_id']) && $view_settings['view_id'] == 758) ) {
if( !empty($query_args['meta_query']) ) {
$query_args['meta_query']['relation'] = 'OR';
}
}
return $query_args;
}
What clause you want to apply between your query filters?
Select items with field:
Container Status is a number equal to 2
AND
Shipment Status is a string equal to 2
AND
Shipment Confirmed Date is a number lower than or equal URL_PARAM(wpv-conf-date)
AND
Container Confirmed Date is a number lower than or equal URL_PARAM(wpv-conf-date)
I think for this to work correctly it would need to have mixed AND/OR conditions something like this:
Select items with field:
[Container Status is a number equal to 2
AND
Container Confirmed Date is a number lower than or equal URL_PARAM(wpv-conf-date)]
OR
[Shipment Status is a string equal to 2
AND
Shipment Confirmed Date is a number lower than or equal URL_PARAM(wpv-conf-date)]
I tested by turning off the 'query-with-or' code snippet, and I saw no change in search behavior. But I'm not sure why using AND returns any results at all. A single post in this view (container/shipment) can't both be Container Status = 2 and Shipment Status = 2 so how is that returning anything at all?
I really appreciate your help on this Minesh, it's been driving me nuts for a bit now.