Skip Navigation

[Resolved] How to count only posts that have one date field not filled out

This support ticket is created 4 years 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.

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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 4 years ago.

Assisted by: Waqar.

Author
Posts
#1572425

Hello there.
Tell us what you are trying to do?

I have a map, where doctors can upload data on patients via upload form.
In the upload form there are some date input fields (custom fields > field type: date). date field A / date field B / and Date field C.

Now i am using a view to count how many of patients are in the database where the date field A has a selected date and the date field B has no selected date field (empty date field).

In the view i use [wpv-found-count] to get a number that i can use in the front end - as statistics.

My problem is the following:
I want to use a two Query Filters in the view:
The first one is

Select items with field:
Covid-19 confirmed is a UNSIGNED lower than or equal TODAY()

this one works fine.

And in the second one i want to have something like
AND
select items with the field:
Negative COVID-19 test "has no date added"

Hope you are all doing well and you cann help....

#1572989

Waqar
Supporter

Languages: English (English )

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

Hi,

Thank you for contacting us and I'd be happy to assist.

For the second part of the query filter ( Negative COVID-19 test "has no date added" ), the comparison type "NOT EXISTS" is needed.

But that type of comparison is not available through the view's "Query Filter" section and you're welcome to submit this as a feature request:
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

For now, as a workaround you can include a custom query filter for this, using the "wpv_filter_query" filter.
( ref: https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query )

For example, suppose that the target view's ID is "123" and the custom field slug for the second field is "negative-covid-19". Then the filtering function will look like this:


add_filter( 'wpv_filter_query', 'filter_empty_date_custom_fn', 1000 , 3 );
function filter_empty_date_custom_fn( $query_args, $view_settings ) {

	if (  ( !is_admin() && isset($view_settings['view_id'] ) ) && ( $view_settings['view_id'] == 123 )  ) 
	{
		$query_args['meta_query'][] =  array(
										'key' => 'wpcf-negative-covid-19',
										'value' => '',
										'type' => 'NUMERIC',
										'compare' => 'NOT EXISTS',
										);
	}

	return $query_args;
}

Please replace view's ID and the custom field slug, as per your website in the above code snippet and it can be included to the website through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through active theme's "functions.php" file.

I hope this helps and for more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

regards,
Waqar

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