Query Loop: Add filter by year
I saw this cool blog and thought it'd be interesting to try the same in WordPress, but the Query Loop block does not provide a filter by date/year control.
Visual
Control
A filter by Month would be nice too. What if you wanted to display posts like a calendar, so all posts in March 2024, March 2023, etc. This blog has a custom archive that filters by month.
Here is a design idea. Please let me know if you have any feedback.
The query filter options include a date option:
Field options for month and year-specific query filters:
Month dropdown field options:
@akasunil that design looks great!
I wonder if filtering by month and year separately would be a bit clearer. It feels a bit convoluted to include them together as "All" months within a year, rather than picking a year, or picking a month and a year.
Can you share examples of queries that would work for date as a generic filter, for month and year?
Thinking about this from a different approach. We have an archives block, with a "Group by" control. Would be great if we could do something similar for the Query loop—but I'm not sure that's possible. That way you wouldn't have to add query loops for each year.
Let's focus on year for this iteration, month next. @dhanson-wp @akasunil is this something either of you could help push forward? It's the simplest path forward.
Let's focus on year for this iteration, month next. @dhanson-wp @akasunil is this something either of you could help push forward? It's the simplest path forward.
That sounds good. I'll give it a try.
@akasunil as a no code person, I'm happy to offer feedback and testing. Going with just the year sounds great to me!
@dhanson-wp PR is ready for review.
@akasunil I finally got around to testing this. The query filter seems to be off by one year. I tested filtering for 2024 and the query returned 2023 posts; 2023 filter displays 2022 posts; and so on.
Tested PR in WordPress Playground https://playground.wordpress.net/gutenberg.html.
The query filter seems to be off by one year. I tested filtering for 2024 and the query returned 2023 posts; 2023 filter displays 2022 posts; and so on.
That's odd. Let me check
It works fine for me. Need exact use case to regenerate this issue.
Here is the WordPress Playground info:
Post dates in WP Admin:
Updating Query Loop with Year Filter:
What else can I share to show what I'm experiencing? Is it something with WordPress Playground? Is there a better method for testing this PR? Thanks @akasunil !