Skip Navigation

[Resolved] Filter stopped working

This support ticket is created 2 years, 6 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.

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 4 replies, has 3 voices.

Last updated by matthewC-9 2 years, 6 months ago.

Assisted by: Waqar.

Author
Posts
#2188107

Hi! We have a filter set up in our functions file that checks for a start and end date on posts in some of our views. The desired behavior is: if a start and/or end date is set, those dates will determine when the post shows; if dates aren't set, the post will display indefinitely. Up until recently, that's how it was working, but now something has changed. Now:
- if start and end dates are set, the post displays based on them as expected
- for new posts: if no start date is set, the post starts displaying immediately as expected
- for existing posts with no end date set: the post displays indefinitely as expected
- but, for new posts with no end date set, or existing posts with an end date removed: the post does not show until an end date is set.

There were several changes that happened around the time that the filter stopped working, so I'm not totally sure what may have made the difference - including updates to a different section of the functions file, and also updates of the Toolset Types and Toolset Views plugins to the latest version.

Here's the code for the filter - again, this was working fine up until recently:

add_filter( 'wpv_filter_query', 'example_function_name', 11, 3 );
function example_function_name( $query_args, $view_settings, $views_id ) {
  if ( $views_id == 126 || $views_id == 1373 || $views_id == 1422 || $views_id == 1466 || $views_id == 3070 ) {
    $query_args['meta_query'][] = array(
      'relation' => 'OR',
      array(
              'key'     => 'wpcf-end-date', 
              'compare' => 'NOT EXISTS',
        ),
      array(
              'key'     => 'wpcf-end-date', 
              'value'   => current_time('timestamp'),
              'compare' => '>',
        ),
    );
    $query_args['meta_query'][] = array(
      'relation' => 'OR',
      array(
              'key'     => 'wpcf-start-date', 
              'compare' => 'NOT EXISTS',
        ),
      array(
              'key'     => 'wpcf-start-date', 
              'value'   => current_time('timestamp'),
              'compare' => '<=',
        ),
    );
  }
  return $query_args;
}

Did anything change in the Toolset plugin updates that this code may no longer be compatible with (but apparently just the end date part)? Or any other ideas about why it's no longer working?

#2188517

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Looking at that code there weren't any changes in Toolset that would account for it no longer working that I'm aware of.

But I do notice one thing which isn't new, that the priority should be higher to ensure that this code runs after other code that could potentially modify the View query so that the changes don't get overwritten. You should use the wpv_filter_query API hook with a priority of 101 or higher (you have 11), so change this:

add_filter( 'wpv_filter_query', 'example_function_name', 11, 3 );

The next step is to check what SQL query (which is what actually interrogates the database) that gets converted to (by WordPress).

Go to Toolset > Settings > Front-end content and enable Views debugging while you check.

Load a page with a View that should be affected by this, and make sure your browser allows the resulting pop-up with the debug info.

You should be able to expand the wpv_filter_query section to confirm the arguments you set up with the above code are intact, and you can also expand the section that shows the corresponding SQL query. Can you share that with us?

#2189235

OK, thank you! I went ahead and updated the priority to 101. With that changed and Views debugging on, here's what I'm getting for one of the affected views:

wpv_filter_query
Array
(
    [post_type] => Array
        (
            [0] => page-arbitrary-featu
        )

    [paged] => 1
    [suppress_filters] => 
    [ignore_sticky_posts] => 1
    [ep_integrate] => 
    [posts_per_page] => -1
    [wpv_original_limit] => -1
    [wpv_original_offset] => 0
    [wpv_original_posts_per_page] => -1
    [meta_query] => Array
        (
            [0] => Array
                (
                    [key] => wpcf-feature-area
                    [value] => 2
                    [type] => NUMERIC
                    [compare] => =
                )

            [relation] => AND
            [1] => Array
                (
                    [relation] => OR
                    [0] => Array
                        (
                            [key] => wpcf-end-date
                            [compare] => NOT EXISTS
                        )

                    [1] => Array
                        (
                            [key] => wpcf-end-date
                            [value] => 1633538148
                            [compare] => >
                        )

                )

            [2] => Array
                (
                    [relation] => OR
                    [0] => Array
                        (
                            [key] => wpcf-start-date
                            [compare] => NOT EXISTS
                        )

                    [1] => Array
                        (
                            [key] => wpcf-start-date
                            [value] => 1633538148
                            [compare] => <=
                        )

                )

        )

    [post_status] => Array
        (
            [0] => publish
            [1] => private
        )

    [post__in] => Array
        (
            [0] => 3705
            [1] => 3729
            [2] => 5905
            [3] => 5918
            [4] => 5924
        )

    [pr_filter_post__in] => Array
        (
            [0] => 3705
            [1] => 3729
            [2] => 5905
            [3] => 5918
            [4] => 5924
        )

    [meta_key] => wpcf-order
    [orderby] => Array
        (
            [meta_value_num] => ASC
            [date] => DESC
        )

    [order] => ASC
    [wpv_orderby] => meta_value_num
    [wpv_order] => ASC
)

Here's the SQL query section:

SELECT   wp_posts.* FROM wp_posts  LEFT JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id )  LEFT JOIN wp_postmeta AS mt1 ON ( wp_posts.ID = mt1.post_id )  LEFT JOIN wp_postmeta AS mt2 ON ( wp_posts.ID = mt2.post_id AND mt2.meta_key = 'wpcf-end-date' )  LEFT JOIN wp_postmeta AS mt3 ON ( wp_posts.ID = mt3.post_id )  LEFT JOIN wp_postmeta AS mt4 ON ( wp_posts.ID = mt4.post_id AND mt4.meta_key = 'wpcf-start-date' )  LEFT JOIN wp_postmeta AS mt5 ON ( wp_posts.ID = mt5.post_id ) LEFT  JOIN wp_icl_translations wpml_translations
							ON wp_posts.ID = wpml_translations.element_id
								AND wpml_translations.element_type = CONCAT('post_', wp_posts.post_type)  WHERE 1=1  AND wp_posts.ID IN (3705,3729,5905,5918,5924) AND ( 
  wp_postmeta.meta_key = 'wpcf-order' 
  AND 
  ( 
    ( mt1.meta_key = 'wpcf-feature-area' AND CAST(mt1.meta_value AS SIGNED) = '2' ) 
    AND 
    ( 
      mt2.post_id IS NULL 
      OR 
      ( mt3.meta_key = 'wpcf-end-date' AND mt3.meta_value > '1633538148' )
    ) 
    AND 
    ( 
      mt4.post_id IS NULL 
      OR 
      ( mt5.meta_key = 'wpcf-start-date' AND mt5.meta_value <= '1633538148' )
    )
  )
) AND wp_posts.post_type = 'page-arbitrary-featu' AND ((wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')) AND ( ( ( wpml_translations.language_code = 'en' OR (
					wpml_translations.language_code = 'en'
					AND wp_posts.post_type IN ( 'post','attachment','view','online-resource','discover-it-online-l','discover-it-online','unique-features','location-arbitrary-f','person','page-arbitrary-featu','common-task','location-common-task','technology','location-technology','rooms','page-common-task','page-online-resource','location','major-program','sponsor','past-program','wpa-helper' )
					AND ( ( 
			( SELECT COUNT(element_id)
			  FROM wp_icl_translations
			  WHERE trid = wpml_translations.trid
			  AND language_code = 'en'
			) = 0
			 ) OR ( 
			( SELECT COUNT(element_id)
				FROM wp_icl_translations t2
				JOIN wp_posts p ON p.id = t2.element_id
				WHERE t2.trid = wpml_translations.trid
				AND t2.language_code = 'en'
				AND (
					p.post_status = 'publish' OR 
					p.post_type='attachment' AND p.post_status = 'inherit'
				)
			) = 0 ) ) 
				) ) AND wp_posts.post_type  IN ('post','page','attachment','wp_block','view','online-resource','discover-it-online-l','discover-it-online','unique-features','arbitrary-feature','location-arbitrary-f','person','page-arbitrary-featu','common-task','location-common-task','technology','location-technology','rooms','page-common-task','page-online-resource','location','alert','major-program','sponsor','past-program','wpa-helper' )  ) OR wp_posts.post_type  NOT  IN ('post','page','attachment','wp_block','view','online-resource','discover-it-online-l','discover-it-online','unique-features','arbitrary-feature','location-arbitrary-f','person','page-arbitrary-featu','common-task','location-common-task','technology','location-technology','rooms','page-common-task','page-online-resource','location','alert','major-program','sponsor','past-program','wpa-helper' )  ) GROUP BY wp_posts.ID ORDER BY wp_postmeta.meta_value+0 ASC, wp_posts.post_date DESC 

Also in case it shows anything interesting, here are the query results with two posts showing, plus another two that should be showing but aren't and have no end date set:

WP_Query Object
(
    [query] => Array
        (
            [post_type] => Array
                (
                    [0] => page-arbitrary-featu
                )

            [paged] => 1
            [suppress_filters] => 
            [ignore_sticky_posts] => 1
            [ep_integrate] => 
            [posts_per_page] => -1
            [wpv_original_limit] => -1
            [wpv_original_offset] => 0
            [wpv_original_posts_per_page] => -1
            [meta_query] => Array
                (
                    [0] => Array
                        (
                            [key] => wpcf-feature-area
                            [value] => 2
                            [type] => NUMERIC
                            [compare] => =
                        )

                    [relation] => AND
                    [1] => Array
                        (
                            [relation] => OR
                            [0] => Array
                                (
                                    [key] => wpcf-end-date
                                    [compare] => NOT EXISTS
                                )

                            [1] => Array
                                (
                                    [key] => wpcf-end-date
                                    [value] => 1633538148
                                    [compare] => >
                                )

                        )

                    [2] => Array
                        (
                            [relation] => OR
                            [0] => Array
                                (
                                    [key] => wpcf-start-date
                                    [compare] => NOT EXISTS
                                )

                            [1] => Array
                                (
                                    [key] => wpcf-start-date
                                    [value] => 1633538148
                                    [compare] => <=
                                )

                        )

                )

            [post_status] => Array
                (
                    [0] => publish
                    [1] => private
                )

            [post__in] => Array
                (
                    [0] => 3705
                    [1] => 3729
                    [2] => 5905
                    [3] => 5918
                    [4] => 5924
                )

            [pr_filter_post__in] => Array
                (
                    [0] => 3705
                    [1] => 3729
                    [2] => 5905
                    [3] => 5918
                    [4] => 5924
                )

            [meta_key] => wpcf-order
            [orderby] => Array
                (
                    [meta_value_num] => ASC
                    [date] => DESC
                )

            [order] => ASC
            [wpv_orderby] => meta_value_num
            [wpv_order] => ASC
            [wpv_query] => 1
        )

    [query_vars] => Array
        (
            [post_type] => Array
                (
                    [0] => page-arbitrary-featu
                )

            [paged] => 1
            [suppress_filters] => 
            [ignore_sticky_posts] => 1
            [ep_integrate] => 
            [posts_per_page] => -1
            [wpv_original_limit] => -1
            [wpv_original_offset] => 0
            [wpv_original_posts_per_page] => -1
            [meta_query] => Array
                (
                    [0] => Array
                        (
                            [key] => wpcf-feature-area
                            [value] => 2
                            [type] => NUMERIC
                            [compare] => =
                        )

                    [relation] => AND
                    [1] => Array
                        (
                            [relation] => OR
                            [0] => Array
                                (
                                    [key] => wpcf-end-date
                                    [compare] => NOT EXISTS
                                )

                            [1] => Array
                                (
                                    [key] => wpcf-end-date
                                    [value] => 1633538148
                                    [compare] => >
                                )

                        )

                    [2] => Array
                        (
                            [relation] => OR
                            [0] => Array
                                (
                                    [key] => wpcf-start-date
                                    [compare] => NOT EXISTS
                                )

                            [1] => Array
                                (
                                    [key] => wpcf-start-date
                                    [value] => 1633538148
                                    [compare] => <=
                                )

                        )

                )

            [post_status] => Array
                (
                    [0] => publish
                    [1] => private
                )

            [post__in] => Array
                (
                    [0] => 3705
                    [1] => 3729
                    [2] => 5905
                    [3] => 5918
                    [4] => 5924
                )

            [pr_filter_post__in] => Array
                (
                    [0] => 3705
                    [1] => 3729
                    [2] => 5905
                    [3] => 5918
                    [4] => 5924
                )

            [meta_key] => wpcf-order
            [orderby] => Array
                (
                    [meta_value_num] => ASC
                    [date] => DESC
                )

            [order] => ASC
            [wpv_orderby] => meta_value_num
            [wpv_order] => ASC
            [wpv_query] => 1
            [error] => 
            [m] => 
            [p] => 0
            [post_parent] => 
            [subpost] => 
            [subpost_id] => 
            [attachment] => 
            [attachment_id] => 0
            [name] => 
            [pagename] => 
            [page_id] => 0
            [second] => 
            [minute] => 
            [hour] => 
            [day] => 0
            [monthnum] => 0
            [year] => 0
            [w] => 0
            [category_name] => 
            [tag] => 
            [cat] => 
            [tag_id] => 
            [author] => 
            [author_name] => 
            [feed] => 
            [tb] => 
            [meta_value] => 
            [preview] => 
            [s] => 
            [sentence] => 
            [title] => 
            [fields] => 
            [menu_order] => 
            [embed] => 
            [category__in] => Array
                (
                )

            [category__not_in] => Array
                (
                )

            [category__and] => Array
                (
                )

            [post__not_in] => Array
                (
                )

            [post_name__in] => Array
                (
                )

            [tag__in] => Array
                (
                )

            [tag__not_in] => Array
                (
                )

            [tag__and] => Array
                (
                )

            [tag_slug__in] => Array
                (
                )

            [tag_slug__and] => Array
                (
                )

            [post_parent__in] => Array
                (
                )

            [post_parent__not_in] => Array
                (
                )

            [author__in] => Array
                (
                )

            [author__not_in] => Array
                (
                )

            [cache_results] => 1
            [update_post_term_cache] => 1
            [lazy_load_term_meta] => 1
            [update_post_meta_cache] => 1
            [nopaging] => 1
            [comments_per_page] => 50
            [no_found_rows] => 
        )

    [tax_query] => WP_Tax_Query Object
        (
            [queries] => Array
                (
                )

            [relation] => AND
            [table_aliases:protected] => Array
                (
                )

            [queried_terms] => Array
                (
                )

            [primary_table] => wp_posts
            [primary_id_column] => ID
        )

    [meta_query] => WP_Meta_Query Object
        (
            [queries] => Array
                (
                    [0] => Array
                        (
                            [key] => wpcf-order
                        )

                    [1] => Array
                        (
                            [0] => Array
                                (
                                    [key] => wpcf-feature-area
                                    [value] => 2
                                    [type] => NUMERIC
                                    [compare] => =
                                )

                            [1] => Array
                                (
                                    [0] => Array
                                        (
                                            [key] => wpcf-end-date
                                            [compare] => NOT EXISTS
                                        )

                                    [1] => Array
                                        (
                                            [key] => wpcf-end-date
                                            [value] => 1633538148
                                            [compare] => >
                                        )

                                    [relation] => OR
                                )

                            [2] => Array
                                (
                                    [0] => Array
                                        (
                                            [key] => wpcf-start-date
                                            [compare] => NOT EXISTS
                                        )

                                    [1] => Array
                                        (
                                            [key] => wpcf-start-date
                                            [value] => 1633538148
                                            [compare] => <=
                                        )

                                    [relation] => OR
                                )

                            [relation] => AND
                        )

                    [relation] => AND
                )

            [relation] => AND
            [meta_table] => wp_postmeta
            [meta_id_column] => post_id
            [primary_table] => wp_posts
            [primary_id_column] => ID
            [table_aliases:protected] => Array
                (
                    [0] => wp_postmeta
                    [1] => mt1
                    [2] => mt2
                    [3] => mt3
                    [4] => mt4
                    [5] => mt5
                )

            [clauses:protected] => Array
                (
                    [wp_postmeta] => Array
                        (
                            [key] => wpcf-order
                            [compare] => =
                            [compare_key] => =
                            [alias] => wp_postmeta
                            [cast] => CHAR
                        )

                    [mt1] => Array
                        (
                            [key] => wpcf-feature-area
                            [value] => 2
                            [type] => NUMERIC
                            [compare] => =
                            [compare_key] => =
                            [alias] => mt1
                            [cast] => SIGNED
                        )

                    [mt2] => Array
                        (
                            [key] => wpcf-end-date
                            [compare] => NOT EXISTS
                            [compare_key] => =
                            [alias] => mt2
                            [cast] => CHAR
                        )

                    [mt3] => Array
                        (
                            [key] => wpcf-end-date
                            [value] => 1633538148
                            [compare] => >
                            [compare_key] => =
                            [alias] => mt3
                            [cast] => CHAR
                        )

                    [mt4] => Array
                        (
                            [key] => wpcf-start-date
                            [compare] => NOT EXISTS
                            [compare_key] => =
                            [alias] => mt4
                            [cast] => CHAR
                        )

                    [mt5] => Array
                        (
                            [key] => wpcf-start-date
                            [value] => 1633538148
                            [compare] => <=
                            [compare_key] => =
                            [alias] => mt5
                            [cast] => CHAR
                        )

                )

            [has_or_relation:protected] => 1
        )

    [date_query] => 
    [request] => SELECT   wp_posts.* FROM wp_posts  LEFT JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id )  LEFT JOIN wp_postmeta AS mt1 ON ( wp_posts.ID = mt1.post_id )  LEFT JOIN wp_postmeta AS mt2 ON ( wp_posts.ID = mt2.post_id AND mt2.meta_key = 'wpcf-end-date' )  LEFT JOIN wp_postmeta AS mt3 ON ( wp_posts.ID = mt3.post_id )  LEFT JOIN wp_postmeta AS mt4 ON ( wp_posts.ID = mt4.post_id AND mt4.meta_key = 'wpcf-start-date' )  LEFT JOIN wp_postmeta AS mt5 ON ( wp_posts.ID = mt5.post_id ) LEFT  JOIN wp_icl_translations wpml_translations
							ON wp_posts.ID = wpml_translations.element_id
								AND wpml_translations.element_type = CONCAT('post_', wp_posts.post_type)  WHERE 1=1  AND wp_posts.ID IN (3705,3729,5905,5918,5924) AND ( 
  wp_postmeta.meta_key = 'wpcf-order' 
  AND 
  ( 
    ( mt1.meta_key = 'wpcf-feature-area' AND CAST(mt1.meta_value AS SIGNED) = '2' ) 
    AND 
    ( 
      mt2.post_id IS NULL 
      OR 
      ( mt3.meta_key = 'wpcf-end-date' AND mt3.meta_value > '1633538148' )
    ) 
    AND 
    ( 
      mt4.post_id IS NULL 
      OR 
      ( mt5.meta_key = 'wpcf-start-date' AND mt5.meta_value <= '1633538148' )
    )
  )
) AND wp_posts.post_type = 'page-arbitrary-featu' AND ((wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')) AND ( ( ( wpml_translations.language_code = 'en' OR (
					wpml_translations.language_code = 'en'
					AND wp_posts.post_type IN ( 'post','attachment','view','online-resource','discover-it-online-l','discover-it-online','unique-features','location-arbitrary-f','person','page-arbitrary-featu','common-task','location-common-task','technology','location-technology','rooms','page-common-task','page-online-resource','location','major-program','sponsor','past-program','wpa-helper' )
					AND ( ( 
			( SELECT COUNT(element_id)
			  FROM wp_icl_translations
			  WHERE trid = wpml_translations.trid
			  AND language_code = 'en'
			) = 0
			 ) OR ( 
			( SELECT COUNT(element_id)
				FROM wp_icl_translations t2
				JOIN wp_posts p ON p.id = t2.element_id
				WHERE t2.trid = wpml_translations.trid
				AND t2.language_code = 'en'
				AND (
					p.post_status = 'publish' OR 
					p.post_type='attachment' AND p.post_status = 'inherit'
				)
			) = 0 ) ) 
				) ) AND wp_posts.post_type  IN ('post','page','attachment','wp_block','view','online-resource','discover-it-online-l','discover-it-online','unique-features','arbitrary-feature','location-arbitrary-f','person','page-arbitrary-featu','common-task','location-common-task','technology','location-technology','rooms','page-common-task','page-online-resource','location','alert','major-program','sponsor','past-program','wpa-helper' )  ) OR wp_posts.post_type  NOT  IN ('post','page','attachment','wp_block','view','online-resource','discover-it-online-l','discover-it-online','unique-features','arbitrary-feature','location-arbitrary-f','person','page-arbitrary-featu','common-task','location-common-task','technology','location-technology','rooms','page-common-task','page-online-resource','location','alert','major-program','sponsor','past-program','wpa-helper' )  ) GROUP BY wp_posts.ID ORDER BY wp_postmeta.meta_value+0 ASC, wp_posts.post_date DESC 
    [posts] => Array
        (
            [0] => WP_Post Object
                (
                    [ID] => 3705
                    [post_author] => 1
                    [post_date] => 2021-05-25 13:04:37
                    [post_date_gmt] => 2021-05-25 17:04:37
                    [post_content] => 
                    [post_title] => Pages Arbitrary features: 1216 - 3704
                    [post_excerpt] => 
                    [post_status] => publish
                    [comment_status] => closed
                    [ping_status] => closed
                    [post_password] => 
                    [post_name] => pages-arbitrary-features-1216-3704
                    [to_ping] => 
                    [pinged] => 
                    [post_modified] => 2021-05-25 13:39:46
                    [post_modified_gmt] => 2021-05-25 17:39:46
                    [post_content_filtered] => 
                    [post_parent] => 0
                    [guid] => <em><u>hidden link</u></em>
                    [menu_order] => 0
                    [post_type] => page-arbitrary-featu
                    [post_mime_type] => 
                    [comment_count] => 0
                    [filter] => raw
                )

            [1] => WP_Post Object
                (
                    [ID] => 5918
                    [post_author] => 1
                    [post_date] => 2021-09-27 00:52:48
                    [post_date_gmt] => 2021-09-27 04:52:48
                    [post_content] => 
                    [post_title] => Pages Arbitrary features: 1216 - 5906
                    [post_excerpt] => 
                    [post_status] => publish
                    [comment_status] => closed
                    [ping_status] => closed
                    [post_password] => 
                    [post_name] => pages-arbitrary-features-1216-5906
                    [to_ping] => 
                    [pinged] => 
                    [post_modified] => 2021-09-27 00:52:48
                    [post_modified_gmt] => 2021-09-27 04:52:48
                    [post_content_filtered] => 
                    [post_parent] => 0
                    [guid] => <em><u>hidden link</u></em>
                    [menu_order] => 0
                    [post_type] => page-arbitrary-featu
                    [post_mime_type] => 
                    [comment_count] => 0
                    [filter] => raw
                )

        )

    [post_count] => 2
    [current_post] => -1
    [in_the_loop] => 
    [post] => WP_Post Object
        (
            [ID] => 3705
            [post_author] => 1
            [post_date] => 2021-05-25 13:04:37
            [post_date_gmt] => 2021-05-25 17:04:37
            [post_content] => 
            [post_title] => Pages Arbitrary features: 1216 - 3704
            [post_excerpt] => 
            [post_status] => publish
            [comment_status] => closed
            [ping_status] => closed
            [post_password] => 
            [post_name] => pages-arbitrary-features-1216-3704
            [to_ping] => 
            [pinged] => 
            [post_modified] => 2021-05-25 13:39:46
            [post_modified_gmt] => 2021-05-25 17:39:46
            [post_content_filtered] => 
            [post_parent] => 0
            [guid] => <em><u>hidden link</u></em>
            [menu_order] => 0
            [post_type] => page-arbitrary-featu
            [post_mime_type] => 
            [comment_count] => 0
            [filter] => raw
        )

    [comment_count] => 0
    [current_comment] => -1
    [found_posts] => 2
    [max_num_pages] => 0
    [max_num_comment_pages] => 0
    [is_single] => 
    [is_preview] => 
    [is_page] => 
    [is_archive] => 
    [is_date] => 
    [is_year] => 
    [is_month] => 
    [is_day] => 
    [is_time] => 
    [is_author] => 
    [is_category] => 
    [is_tag] => 
    [is_tax] => 
    [is_search] => 
    [is_feed] => 
    [is_comment_feed] => 
    [is_trackback] => 
    [is_home] => 1
    [is_privacy_policy] => 
    [is_404] => 
    [is_embed] => 
    [is_paged] => 
    [is_admin] => 
    [is_attachment] => 
    [is_singular] => 
    [is_robots] => 
    [is_favicon] => 
    [is_posts_page] => 
    [is_post_type_archive] => 
    [query_vars_hash:WP_Query:private] => 90e7c8270d30ba5ea96fdd551b8cff29
    [query_vars_changed:WP_Query:private] => 
    [thumbnails_cached] => 
    [stopwords:WP_Query:private] => 
    [compat_fields:WP_Query:private] => Array
        (
            [0] => query_vars_hash
            [1] => query_vars_changed
        )

    [compat_methods:WP_Query:private] => Array
        (
            [0] => init_query_flags
            [1] => parse_tax_query
        )

)

And here are the results with the same posts connected, but an end date added to the other 2 (so now 4 show)"

WP_Query Object
(
    [query] => Array
        (
            [post_type] => Array
                (
                    [0] => page-arbitrary-featu
                )

            [paged] => 1
            [suppress_filters] => 
            [ignore_sticky_posts] => 1
            [ep_integrate] => 
            [posts_per_page] => -1
            [wpv_original_limit] => -1
            [wpv_original_offset] => 0
            [wpv_original_posts_per_page] => -1
            [meta_query] => Array
                (
                    [0] => Array
                        (
                            [key] => wpcf-feature-area
                            [value] => 2
                            [type] => NUMERIC
                            [compare] => =
                        )

                    [relation] => AND
                    [1] => Array
                        (
                            [relation] => OR
                            [0] => Array
                                (
                                    [key] => wpcf-end-date
                                    [compare] => NOT EXISTS
                                )

                            [1] => Array
                                (
                                    [key] => wpcf-end-date
                                    [value] => 1633538742
                                    [compare] => >
                                )

                        )

                    [2] => Array
                        (
                            [relation] => OR
                            [0] => Array
                                (
                                    [key] => wpcf-start-date
                                    [compare] => NOT EXISTS
                                )

                            [1] => Array
                                (
                                    [key] => wpcf-start-date
                                    [value] => 1633538742
                                    [compare] => <=
                                )

                        )

                )

            [post_status] => Array
                (
                    [0] => publish
                    [1] => private
                )

            [post__in] => Array
                (
                    [0] => 3705
                    [1] => 3729
                    [2] => 5905
                    [3] => 5918
                    [4] => 5925
                )

            [pr_filter_post__in] => Array
                (
                    [0] => 3705
                    [1] => 3729
                    [2] => 5905
                    [3] => 5918
                    [4] => 5925
                )

            [meta_key] => wpcf-order
            [orderby] => Array
                (
                    [meta_value_num] => ASC
                    [date] => DESC
                )

            [order] => ASC
            [wpv_orderby] => meta_value_num
            [wpv_order] => ASC
            [wpv_query] => 1
        )

    [query_vars] => Array
        (
            [post_type] => Array
                (
                    [0] => page-arbitrary-featu
                )

            [paged] => 1
            [suppress_filters] => 
            [ignore_sticky_posts] => 1
            [ep_integrate] => 
            [posts_per_page] => -1
            [wpv_original_limit] => -1
            [wpv_original_offset] => 0
            [wpv_original_posts_per_page] => -1
            [meta_query] => Array
                (
                    [0] => Array
                        (
                            [key] => wpcf-feature-area
                            [value] => 2
                            [type] => NUMERIC
                            [compare] => =
                        )

                    [relation] => AND
                    [1] => Array
                        (
                            [relation] => OR
                            [0] => Array
                                (
                                    [key] => wpcf-end-date
                                    [compare] => NOT EXISTS
                                )

                            [1] => Array
                                (
                                    [key] => wpcf-end-date
                                    [value] => 1633538742
                                    [compare] => >
                                )

                        )

                    [2] => Array
                        (
                            [relation] => OR
                            [0] => Array
                                (
                                    [key] => wpcf-start-date
                                    [compare] => NOT EXISTS
                                )

                            [1] => Array
                                (
                                    [key] => wpcf-start-date
                                    [value] => 1633538742
                                    [compare] => <=
                                )

                        )

                )

            [post_status] => Array
                (
                    [0] => publish
                    [1] => private
                )

            [post__in] => Array
                (
                    [0] => 3705
                    [1] => 3729
                    [2] => 5905
                    [3] => 5918
                    [4] => 5925
                )

            [pr_filter_post__in] => Array
                (
                    [0] => 3705
                    [1] => 3729
                    [2] => 5905
                    [3] => 5918
                    [4] => 5925
                )

            [meta_key] => wpcf-order
            [orderby] => Array
                (
                    [meta_value_num] => ASC
                    [date] => DESC
                )

            [order] => ASC
            [wpv_orderby] => meta_value_num
            [wpv_order] => ASC
            [wpv_query] => 1
            [error] => 
            [m] => 
            [p] => 0
            [post_parent] => 
            [subpost] => 
            [subpost_id] => 
            [attachment] => 
            [attachment_id] => 0
            [name] => 
            [pagename] => 
            [page_id] => 0
            [second] => 
            [minute] => 
            [hour] => 
            [day] => 0
            [monthnum] => 0
            [year] => 0
            [w] => 0
            [category_name] => 
            [tag] => 
            [cat] => 
            [tag_id] => 
            [author] => 
            [author_name] => 
            [feed] => 
            [tb] => 
            [meta_value] => 
            [preview] => 
            [s] => 
            [sentence] => 
            [title] => 
            [fields] => 
            [menu_order] => 
            [embed] => 
            [category__in] => Array
                (
                )

            [category__not_in] => Array
                (
                )

            [category__and] => Array
                (
                )

            [post__not_in] => Array
                (
                )

            [post_name__in] => Array
                (
                )

            [tag__in] => Array
                (
                )

            [tag__not_in] => Array
                (
                )

            [tag__and] => Array
                (
                )

            [tag_slug__in] => Array
                (
                )

            [tag_slug__and] => Array
                (
                )

            [post_parent__in] => Array
                (
                )

            [post_parent__not_in] => Array
                (
                )

            [author__in] => Array
                (
                )

            [author__not_in] => Array
                (
                )

            [cache_results] => 1
            [update_post_term_cache] => 1
            [lazy_load_term_meta] => 1
            [update_post_meta_cache] => 1
            [nopaging] => 1
            [comments_per_page] => 50
            [no_found_rows] => 
        )

    [tax_query] => WP_Tax_Query Object
        (
            [queries] => Array
                (
                )

            [relation] => AND
            [table_aliases:protected] => Array
                (
                )

            [queried_terms] => Array
                (
                )

            [primary_table] => wp_posts
            [primary_id_column] => ID
        )

    [meta_query] => WP_Meta_Query Object
        (
            [queries] => Array
                (
                    [0] => Array
                        (
                            [key] => wpcf-order
                        )

                    [1] => Array
                        (
                            [0] => Array
                                (
                                    [key] => wpcf-feature-area
                                    [value] => 2
                                    [type] => NUMERIC
                                    [compare] => =
                                )

                            [1] => Array
                                (
                                    [0] => Array
                                        (
                                            [key] => wpcf-end-date
                                            [compare] => NOT EXISTS
                                        )

                                    [1] => Array
                                        (
                                            [key] => wpcf-end-date
                                            [value] => 1633538742
                                            [compare] => >
                                        )

                                    [relation] => OR
                                )

                            [2] => Array
                                (
                                    [0] => Array
                                        (
                                            [key] => wpcf-start-date
                                            [compare] => NOT EXISTS
                                        )

                                    [1] => Array
                                        (
                                            [key] => wpcf-start-date
                                            [value] => 1633538742
                                            [compare] => <=
                                        )

                                    [relation] => OR
                                )

                            [relation] => AND
                        )

                    [relation] => AND
                )

            [relation] => AND
            [meta_table] => wp_postmeta
            [meta_id_column] => post_id
            [primary_table] => wp_posts
            [primary_id_column] => ID
            [table_aliases:protected] => Array
                (
                    [0] => wp_postmeta
                    [1] => mt1
                    [2] => mt2
                    [3] => mt3
                    [4] => mt4
                    [5] => mt5
                )

            [clauses:protected] => Array
                (
                    [wp_postmeta] => Array
                        (
                            [key] => wpcf-order
                            [compare] => =
                            [compare_key] => =
                            [alias] => wp_postmeta
                            [cast] => CHAR
                        )

                    [mt1] => Array
                        (
                            [key] => wpcf-feature-area
                            [value] => 2
                            [type] => NUMERIC
                            [compare] => =
                            [compare_key] => =
                            [alias] => mt1
                            [cast] => SIGNED
                        )

                    [mt2] => Array
                        (
                            [key] => wpcf-end-date
                            [compare] => NOT EXISTS
                            [compare_key] => =
                            [alias] => mt2
                            [cast] => CHAR
                        )

                    [mt3] => Array
                        (
                            [key] => wpcf-end-date
                            [value] => 1633538742
                            [compare] => >
                            [compare_key] => =
                            [alias] => mt3
                            [cast] => CHAR
                        )

                    [mt4] => Array
                        (
                            [key] => wpcf-start-date
                            [compare] => NOT EXISTS
                            [compare_key] => =
                            [alias] => mt4
                            [cast] => CHAR
                        )

                    [mt5] => Array
                        (
                            [key] => wpcf-start-date
                            [value] => 1633538742
                            [compare] => <=
                            [compare_key] => =
                            [alias] => mt5
                            [cast] => CHAR
                        )

                )

            [has_or_relation:protected] => 1
        )

    [date_query] => 
    [request] => SELECT   wp_posts.* FROM wp_posts  LEFT JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id )  LEFT JOIN wp_postmeta AS mt1 ON ( wp_posts.ID = mt1.post_id )  LEFT JOIN wp_postmeta AS mt2 ON ( wp_posts.ID = mt2.post_id AND mt2.meta_key = 'wpcf-end-date' )  LEFT JOIN wp_postmeta AS mt3 ON ( wp_posts.ID = mt3.post_id )  LEFT JOIN wp_postmeta AS mt4 ON ( wp_posts.ID = mt4.post_id AND mt4.meta_key = 'wpcf-start-date' )  LEFT JOIN wp_postmeta AS mt5 ON ( wp_posts.ID = mt5.post_id ) LEFT  JOIN wp_icl_translations wpml_translations
							ON wp_posts.ID = wpml_translations.element_id
								AND wpml_translations.element_type = CONCAT('post_', wp_posts.post_type)  WHERE 1=1  AND wp_posts.ID IN (3705,3729,5905,5918,5925) AND ( 
  wp_postmeta.meta_key = 'wpcf-order' 
  AND 
  ( 
    ( mt1.meta_key = 'wpcf-feature-area' AND CAST(mt1.meta_value AS SIGNED) = '2' ) 
    AND 
    ( 
      mt2.post_id IS NULL 
      OR 
      ( mt3.meta_key = 'wpcf-end-date' AND mt3.meta_value > '1633538742' )
    ) 
    AND 
    ( 
      mt4.post_id IS NULL 
      OR 
      ( mt5.meta_key = 'wpcf-start-date' AND mt5.meta_value <= '1633538742' )
    )
  )
) AND wp_posts.post_type = 'page-arbitrary-featu' AND ((wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')) AND ( ( ( wpml_translations.language_code = 'en' OR (
					wpml_translations.language_code = 'en'
					AND wp_posts.post_type IN ( 'post','attachment','view','online-resource','discover-it-online-l','discover-it-online','unique-features','location-arbitrary-f','person','page-arbitrary-featu','common-task','location-common-task','technology','location-technology','rooms','page-common-task','page-online-resource','location','major-program','sponsor','past-program','wpa-helper' )
					AND ( ( 
			( SELECT COUNT(element_id)
			  FROM wp_icl_translations
			  WHERE trid = wpml_translations.trid
			  AND language_code = 'en'
			) = 0
			 ) OR ( 
			( SELECT COUNT(element_id)
				FROM wp_icl_translations t2
				JOIN wp_posts p ON p.id = t2.element_id
				WHERE t2.trid = wpml_translations.trid
				AND t2.language_code = 'en'
				AND (
					p.post_status = 'publish' OR 
					p.post_type='attachment' AND p.post_status = 'inherit'
				)
			) = 0 ) ) 
				) ) AND wp_posts.post_type  IN ('post','page','attachment','wp_block','view','online-resource','discover-it-online-l','discover-it-online','unique-features','arbitrary-feature','location-arbitrary-f','person','page-arbitrary-featu','common-task','location-common-task','technology','location-technology','rooms','page-common-task','page-online-resource','location','alert','major-program','sponsor','past-program','wpa-helper' )  ) OR wp_posts.post_type  NOT  IN ('post','page','attachment','wp_block','view','online-resource','discover-it-online-l','discover-it-online','unique-features','arbitrary-feature','location-arbitrary-f','person','page-arbitrary-featu','common-task','location-common-task','technology','location-technology','rooms','page-common-task','page-online-resource','location','alert','major-program','sponsor','past-program','wpa-helper' )  ) GROUP BY wp_posts.ID ORDER BY wp_postmeta.meta_value+0 ASC, wp_posts.post_date DESC 
    [posts] => Array
        (
            [0] => WP_Post Object
                (
                    [ID] => 3705
                    [post_author] => 1
                    [post_date] => 2021-05-25 13:04:37
                    [post_date_gmt] => 2021-05-25 17:04:37
                    [post_content] => 
                    [post_title] => Pages Arbitrary features: 1216 - 3704
                    [post_excerpt] => 
                    [post_status] => publish
                    [comment_status] => closed
                    [ping_status] => closed
                    [post_password] => 
                    [post_name] => pages-arbitrary-features-1216-3704
                    [to_ping] => 
                    [pinged] => 
                    [post_modified] => 2021-05-25 13:39:46
                    [post_modified_gmt] => 2021-05-25 17:39:46
                    [post_content_filtered] => 
                    [post_parent] => 0
                    [guid] => <em><u>hidden link</u></em>
                    [menu_order] => 0
                    [post_type] => page-arbitrary-featu
                    [post_mime_type] => 
                    [comment_count] => 0
                    [filter] => raw
                )

            [1] => WP_Post Object
                (
                    [ID] => 5925
                    [post_author] => 1
                    [post_date] => 2021-10-06 16:45:03
                    [post_date_gmt] => 2021-10-06 20:45:03
                    [post_content] => 
                    [post_title] => Pages Arbitrary features: 1216 - 3699
                    [post_excerpt] => 
                    [post_status] => publish
                    [comment_status] => closed
                    [ping_status] => closed
                    [post_password] => 
                    [post_name] => pages-arbitrary-features-1216-3699
                    [to_ping] => 
                    [pinged] => 
                    [post_modified] => 2021-10-06 16:45:03
                    [post_modified_gmt] => 2021-10-06 20:45:03
                    [post_content_filtered] => 
                    [post_parent] => 0
                    [guid] => <em><u>hidden link</u></em>
                    [menu_order] => 0
                    [post_type] => page-arbitrary-featu
                    [post_mime_type] => 
                    [comment_count] => 0
                    [filter] => raw
                )

            [2] => WP_Post Object
                (
                    [ID] => 5918
                    [post_author] => 1
                    [post_date] => 2021-09-27 00:52:48
                    [post_date_gmt] => 2021-09-27 04:52:48
                    [post_content] => 
                    [post_title] => Pages Arbitrary features: 1216 - 5906
                    [post_excerpt] => 
                    [post_status] => publish
                    [comment_status] => closed
                    [ping_status] => closed
                    [post_password] => 
                    [post_name] => pages-arbitrary-features-1216-5906
                    [to_ping] => 
                    [pinged] => 
                    [post_modified] => 2021-09-27 00:52:48
                    [post_modified_gmt] => 2021-09-27 04:52:48
                    [post_content_filtered] => 
                    [post_parent] => 0
                    [guid] => <em><u>hidden link</u></em>
                    [menu_order] => 0
                    [post_type] => page-arbitrary-featu
                    [post_mime_type] => 
                    [comment_count] => 0
                    [filter] => raw
                )

            [3] => WP_Post Object
                (
                    [ID] => 5905
                    [post_author] => 1
                    [post_date] => 2021-09-26 23:12:02
                    [post_date_gmt] => 2021-09-27 03:12:02
                    [post_content] => 
                    [post_title] => Pages Arbitrary features: 1216 - 5830
                    [post_excerpt] => 
                    [post_status] => publish
                    [comment_status] => closed
                    [ping_status] => closed
                    [post_password] => 
                    [post_name] => pages-arbitrary-features-1216-5830
                    [to_ping] => 
                    [pinged] => 
                    [post_modified] => 2021-10-06 16:45:37
                    [post_modified_gmt] => 2021-10-06 20:45:37
                    [post_content_filtered] => 
                    [post_parent] => 0
                    [guid] => <em><u>hidden link</u></em>
                    [menu_order] => 0
                    [post_type] => page-arbitrary-featu
                    [post_mime_type] => 
                    [comment_count] => 0
                    [filter] => raw
                )

        )

    [post_count] => 4
    [current_post] => -1
    [in_the_loop] => 
    [post] => WP_Post Object
        (
            [ID] => 3705
            [post_author] => 1
            [post_date] => 2021-05-25 13:04:37
            [post_date_gmt] => 2021-05-25 17:04:37
            [post_content] => 
            [post_title] => Pages Arbitrary features: 1216 - 3704
            [post_excerpt] => 
            [post_status] => publish
            [comment_status] => closed
            [ping_status] => closed
            [post_password] => 
            [post_name] => pages-arbitrary-features-1216-3704
            [to_ping] => 
            [pinged] => 
            [post_modified] => 2021-05-25 13:39:46
            [post_modified_gmt] => 2021-05-25 17:39:46
            [post_content_filtered] => 
            [post_parent] => 0
            [guid] => <em><u>hidden link</u></em>
            [menu_order] => 0
            [post_type] => page-arbitrary-featu
            [post_mime_type] => 
            [comment_count] => 0
            [filter] => raw
        )

    [comment_count] => 0
    [current_comment] => -1
    [found_posts] => 4
    [max_num_pages] => 0
    [max_num_comment_pages] => 0
    [is_single] => 
    [is_preview] => 
    [is_page] => 
    [is_archive] => 
    [is_date] => 
    [is_year] => 
    [is_month] => 
    [is_day] => 
    [is_time] => 
    [is_author] => 
    [is_category] => 
    [is_tag] => 
    [is_tax] => 
    [is_search] => 
    [is_feed] => 
    [is_comment_feed] => 
    [is_trackback] => 
    [is_home] => 1
    [is_privacy_policy] => 
    [is_404] => 
    [is_embed] => 
    [is_paged] => 
    [is_admin] => 
    [is_attachment] => 
    [is_singular] => 
    [is_robots] => 
    [is_favicon] => 
    [is_posts_page] => 
    [is_post_type_archive] => 
    [query_vars_hash:WP_Query:private] => 62a8ad9096f65bd9436d0ad26fc8b967
    [query_vars_changed:WP_Query:private] => 
    [thumbnails_cached] => 
    [stopwords:WP_Query:private] => 
    [compat_fields:WP_Query:private] => Array
        (
            [0] => query_vars_hash
            [1] => query_vars_changed
        )

    [compat_methods:WP_Query:private] => Array
        (
            [0] => init_query_flags
            [1] => parse_tax_query
        )

)

Let me know if anything else may be useful--

#2189741

Waqar
Supporter

Languages: English (English )

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

Thanks for writing back and for sharing these details.

I'm not sure exactly how long before you implemented this and got it to work, but I can think of an update, after which an empty custom field record is now added, even if no date is selected in the date type field.

After that change, it would make sense to replace "NOT EXISTS" check with a check for an empty value. For example:


add_filter( 'wpv_filter_query', 'example_function_name', 11, 3 );
function example_function_name( $query_args, $view_settings, $views_id ) {
  if ( $views_id == 126 || $views_id == 1373 || $views_id == 1422 || $views_id == 1466 || $views_id == 3070 ) {
    $query_args['meta_query'][] = array(
      'relation' => 'OR',
      array(
              'key'     => 'wpcf-end-date',
              'value'   => '',
              'compare' => '=',
        ),
      array(
              'key'     => 'wpcf-end-date', 
              'value'   => current_time('timestamp'),
              'compare' => '>',
        ),
    );
    $query_args['meta_query'][] = array(
      'relation' => 'OR',
      array(
              'key'     => 'wpcf-start-date',
              'value'   => '',
              'compare' => '=',
        ),
      array(
              'key'     => 'wpcf-start-date', 
              'value'   => current_time('timestamp'),
              'compare' => '<=',
        ),
    );
  }
  return $query_args;
}

Note: For any new posts that you've added, without entering any start and/or end date, you'll see that an empty record for both these fields will still be added in the "postmeta" table. But for older posts, please check if empty records for these fields exist, and if not, you can update them once from the admin area post edit screen, which will add those empty field records.

#2193053

Aha!! Yes, that change seems to do it. Thanks Waqar and Nigel for your help!

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