Skip Navigation

[Resolved] query filter by date not working

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

Our next available supporter will start replying to tickets in about 2.01 hours from now. 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/Hong_Kong (GMT+08:00)

This topic contains 16 replies, has 2 voices.

Last updated by franzG-4 3 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#1989405

Tell us what you are trying to do?

hello, I am using toolset block editor for setting up views. One of my views includes several front-end filters such as full text search, filtering by taxonomy... and a date filter with the function BETWEEN, based on a custom date field. This filter works fine, I am able to define an exact starting date and an exact end date to display only the posts created in this time lap. So far, so good.

So recently I tried to define a query filter (block editor > view > right column > content selection > filter) for date filering, because in some moments, I want to propose a fixed date range of posts to our users.

Input type / field type: string; filtering BETWEEN; exact starting and end date (d.m.y.).

This filter does not work at all, I tried other parameters (MONTH, ....other type such as date, etc.). No success.

Is there a conflict between front and filters and query filter? What might the reasons for the failure of the query filter?

Kind regards

Franz

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#1989933
date-filter.JPG

Hello,

I have tried it in a fresh WP installation + the latest version of Toolset plugins, it works fine.

For example, filter by:
Select posts whose
Published date belongs to a year between those: 2021,2021
AND
Published date belongs to a month between those: 3,3
AND
Published date belongs to a day between those: 17,18

I can get posts published in today(2021-3-17)

See my screenshot date-filter.JPG

I suggest you do the normal debug steps, for example:

1) Make sure you are using the latest version of Toolset plugins, you can download them here:
https://toolset.com/account/downloads/

2) In case it is a compatibility problem, please deactivate all other plugins, and switch to WordPress default theme 2021, deactivate all custom PHP/JS code snippets, and test again

3) Also check if there is any PHP/JS error in your website:
https://toolset.com/documentation/programmer-reference/debugging-sites-built-with-toolset/

#1990405
Screenshot custom date filter.png

hello Luo Yang,

many thanks for your answer. We are using the latest version of Toolset and the theme Generate Press, which is recommanded by Toolset. In your test, you used the PUBLISHED POST DATE. I could reproduce this test, no problems!

But we are using a CUSTOM POST DATE FIELD, that we use for front-end filtering of the posts (based on Toolset instructions, the filtering of posts can only be made by custom date and not by default post date, right?).

https://toolset.com/forums/topic/custom-fields-7/

In addition, we offer a legal service, where quite often the default published date does not correspond to the manually entered date. But the latter is, for some reason, the date which is important for our readers.

So I tried to define a query filter with the CUSTOM DATE FIELD as illustrated in my printscreen. I defined first the custom date as "DATE", as shown in the printscreen, tried after also with "NUMBER" as date format. In this example, I want to display posts having a custom post date originating from the custom field between December 17th to December 31th 2020. So I used the condition BETWEEN. Did not work.

Do you have an idea, why this filter does not work?

Many thanks for the exchange!
Franz

#1991623
number.JPG

The custom date field stores value in timestamp format.

Please try this:
In your screenshot:
https://toolset.com/wp-content/uploads/2021/03/1990405-Screenshot_custom_date_filter.png

Change the option "date" to "number", see my screenshot number.JPG

More help:
https://toolset.com/documentation/user-guides/views/date-filters/

#1992077
Query filter non-of-the -following not working.png
Date as number not working.png

hello Luo Yang,

many thanks for your answer. I reproduced exactly what you did, i.e. custom field with the setting "number" (Anzahl), function BETWEEN 2 exact dates (see screenshot, it does not work. No filtering is done.

I am wondering, if I have a fundamental problem with query filtering on my website: I tested additionnally filtering with different taxonomies, which I defined for this custom post type. With taxonomy "Type of publication" which is assigned only once to a post, filtering worked. For taxonomy "branch" (industrial sector), where each post contains more than one assigned taxonomy term, filtering by "none of the following" and crossing all the terms (see screenshot) resulted in no filtering effect. But this constellation should result in "zero posts"?

It seems, filtering by query filters works in some cases, in other not at all. Do you have any hints how to proceed? Or is there an conflict between front-end filters and query filters? Taxonomy "branch" and "custom post date" are both front-end filters, taxonomy "publication type" not....

Kind regards

Franz

#1992943

Please provide a test site with the same problem, also point out the problem page URLs, I need to test and debug it in a live website, thanks

#1993169

I can login into your website, but it keeps on log me out automatically no more than one minute, it is hard to debug the problem in such kind of environment, can you check it?

You can also provide a database dump file in below private message box, so I can try to duplicate the same problem and debug it in my localhost, thanks
https://toolset.com/faq/provide-supporters-copy-site/

#1995521

I am downloading the files, will update here if find anything

#1995605

I can install your duplicator package file in my localhost.

I have tried below steps:
1) Deactivate all other plugins, switch to WP default theme 2021
2) Edit the problem page:
hidden link
3) Find and edit the view block, add a filter same as your screenshot:
https://toolset.com/wp-content/uploads/2021/03/1992077-Query_filter_non_of_the_following_not_working.png
4) Save, and test it in front-end, date field "Datum Beitrag", choose:
31/10/2020 ~ 22/03/2021

It works fine, I can see some items in the result.

Is there anything missing? please provide detail steps to reproduce the same problem:
filtering by query filters works in some cases, in other not at all.

#1995689

Many thanks!
so it seems, that the problem maybe comes from other plugins?

However, the date range you tested includes all posts, so filtering cannot really be tested. Could you try the following range

21/12/2020 ~ 22/03/2021

you should find 2 posts only.

Kind regards

Franz

#1996959
date-range.JPG

Nope, there are lots of posts in your website are using "Datum Beitrag" value in 21/12/2020 ~ 22/03/2021, see my screenshot date-range.JPG, you can check them in your website one by one.

And you did not answer my above question:
please provide detail steps to reproduce the same problem:
filtering by query filters works in some cases, in other not at all.

#1997171
Result front end query filter none of the following taxonomies.png
Query filter none of the following taxonomies.png
Result front end query filter type of publication.png
Query filter type of publication.png
Result front end query filter date range.png
Date range query filter.png
Date range filtering front end.png
1996959-date_range.jpg
Date range backend.png

hello,
I try one by one to explain:

Date range
"Nope, there are lots of posts in your website are using "Datum Beitrag" value in
21/12/2020 ~ 22/03/2021, see my screenshot date-range.JPG, you can check them in your website one by one."

That is your conclusion, and you add a screenshot, where posts are displayed from the 20/12/2020 !!!!!!!! (1996959-date_range). Please look at the details, you filtered the posts for a range 21/12/2020 ~ 22/03/2021, but you got results which are OUTSIDE this range (20/12/2020), which shows, that the query filter is not working correctly!

There are exactly 2 posts in the range of 21/12/2020 ~ 22/03/2021 (see screenshot Date range backend, I sorted the list of posts so the most recent are displayed first). I used the front end filter to filter for the same date range (see screenshot Date range filtering front end), and I got 2 posts as expected. But when I define the same date range in the query filter section of the view (see screenshot Date range query filter), I get 144 post front end, that means no filtering! (see screenshot Result front end query filter date range).

Query filter working
In this custom post, we use also a taxonomy "Beitragsart" which means "Type of publication". Filtering for one term (see screenshot Query filter type of publication) gives the correct result front end, i.e. one publication (see screenshot Result front end query filter type of publication).

Another query filter not working
I defined a query filter "none of the following" and I crossed all taxonomies (see screenshot Query filter none of the following taxonomies). This filter should lead to zero posts, if all post are assigned to a taxonomy, do you agree? But the result front end is, that all 144 posts are displayed (see screenshot Result front end query filter none of the following taxonomies). So the filter is not working

Please consider my information, I feel misunderstood by your answers .... don't know, if there is a misunderstanding.

Franz

#1997331
Screenshot.jpg

Sorry for the misunderstandings

Q1) I have tried it with your duplicator package in my localhost(Deactivate all other plugins, with only Toolset plugins + 2021 theme), filter the result in date range 21/12/2020 ~ 22/03/2021, I do see two items in the result, see my screenshot: Screenshot.jpg

Q2) Another query filter not working
I can see the problem in my localhost, checking it, and will update here if find anything

#1997385

For the second question:
Another query filter not working

The problem is:
There is taxonomy filter field "Branchen" in the custom search form, it will override, the taxonomy filter "Branchen" of view block, and conducts the problem you mentioned above.

I assume you are going to display only the search form by default, if it is, please follow our document to display the search form and search result in two pages:
https://toolset.com/course-lesson/displaying-search-results-on-a-different-page/

#1997607

Dear Luo Yang,

many thanks for your tests and sorry for the time, you are wasting with me. Just 2 remarks:

- you conducted the test in Q1 with the post date, but not with the custom field "Datum Beitrag". With post date, query filter is working, but not for the custom field. If you would repeat the test with the custom field, probably the filter will also fail.

- Q2: Do you have any idea about the resason for the failure? Is that a bug? I am just asking because we will go public with our website in 2-3 months and the question arrises for me, if I should implement all the queries with another plugin.

So have a god day! Kind regards

Franz