Skip Navigation

[Resolved] Display Posts Based on Taxonomy and Current Date

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

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 2 replies, has 2 voices.

Last updated by mikeL-12 6 years, 1 month ago.

Assisted by: Nigel.

Author
Posts
#1163462

Tell us what you are trying to do?
I have a website for movie games and I have a 'Featured Games' slider at the top of my main page that displays games that are currently relevant based on today's date. i.e. display Christmas movies from December 1st to December 31st. Currently this has been a manual act for me by setting a 'Featured Movie' custom checkbox field within the post and displaying within my slider based on that.

I'm hoping to automate this process a bit more, what I've done is created a custom taxonomy called "Collections" and created a "Christmas" collection to be added to each of the posts that I deem it should match. Where I'm running into problems is that when I'm trying to create a conditional output for the Loop (or custom search), or within the query filter of the view itself to match on the proper collection, I don't have any option that I can match on current date. I have the option to match on post date but not current date. Am I missing something?

Is there any documentation that you are following?
I've searched through the Support forum as well as the Community support forum as well, but haven't really found anybody asking specifically about referencing today's date when displaying a view output.

Is there a similar example that we can see?
Not that I've found I guess.

What is the link to your site?
hidden link

#1163639

Nigel
Supporter

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

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

Hi Mike

"I have the option to match on post date but not current date."

When you add query filters to a View you are comparing against something.

So when using post date, for example, you can set up the View that queries the database for posts to say "only return posts whose post_date is later than 1 Jan 2018" which would only retrieve posts published this year. Bringing "today" into the mix, you could say "only return posts whose post_date is later than today" which would retrieve posts that are scheduled for publication but not yet published.

"Today" is being compared against the "post_date" field value of each possibly matching post.

It seems like you are describing something very different.

"If today is a day in December then show posts with the 'Christmas' category", or something similar.

In which case, we are really talking about optionally applying a taxonomy filter depending on some particular date-related condition.

That's not something you can set up in the GUI, you would need to write some custom PHP for that, where you use the wpv_filter_query API hook to trigger code that checks the current date and infers what taxonomy term to filter by.

The simplest version would be a series of if-then statements (if today is mid- to end-October then show posts with the "Halloween" category, if today is December, Christmas etc.).

If you wanted to get a little more sophisticated you could add term meta for the applicable dates to each seasonal category and add new ones in the WP backend, including the dates, and have it applied entirely automatically.

That implies more complex code, and I'm not sure what you are comfortable with. I can't write the code for you, but if you try and get stuck I will be happy to help, or you could recruit a Toolset Contractor to do it for you: toolset.com/contractors/

https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

#1163996

Thanks Nigel, I figured that would probably be the case but I wanted to make sure that I wasn't missing something obvious. Is there any room for a feature request to be able to utilize dates other than the post date when building a view (or conditional formatting)? If so, that would be wonderful!

Your help is very much appreciated!