gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Query Loop: Add filter by year

Open richtabor opened this issue 1 year ago • 4 comments

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

CleanShot 2024-01-29 at 12 24 56

Control

CleanShot 2024-01-29 at 12 26 57

richtabor avatar Jan 29 '24 17:01 richtabor

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.

dhanson-wp avatar Mar 09 '24 15:03 dhanson-wp

Here is a design idea. Please let me know if you have any feedback.

The query filter options include a date option: Screenshot at Jun 24 10-45-52

Field options for month and year-specific query filters: Screenshot at Jun 24 10-51-43

Month dropdown field options: Screenshot at Jun 24 10-58-51

akasunil avatar Jun 24 '24 05:06 akasunil

@akasunil that design looks great!

dhanson-wp avatar Jun 24 '24 11:06 dhanson-wp

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?

richtabor avatar Jul 01 '24 01:07 richtabor

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.

CleanShot 2024-07-31 at 09 50 57

richtabor avatar Jul 31 '24 13:07 richtabor

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.

CleanShot 2024-07-31 at 09 49 00

richtabor avatar Jul 31 '24 13:07 richtabor

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 avatar Jul 31 '24 14:07 akasunil

@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 avatar Jul 31 '24 16:07 dhanson-wp

@dhanson-wp PR is ready for review.

akasunil avatar Sep 17 '24 13:09 akasunil

@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. Markup 2024-09-24 at 07 11 07

Tested PR in WordPress Playground https://playground.wordpress.net/gutenberg.html.

dhanson-wp avatar Sep 24 '24 12:09 dhanson-wp

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

akasunil avatar Sep 25 '24 08:09 akasunil

It works fine for me. Need exact use case to regenerate this issue.

20240925_143849

akasunil avatar Sep 25 '24 09:09 akasunil

Here is the WordPress Playground info: Markup 2024-09-25 at 09 54 39

Post dates in WP Admin: Markup 2024-09-25 at 09 57 11

Updating Query Loop with Year Filter: Screen Capture Sept 25 at 09-59

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 !

dhanson-wp avatar Sep 25 '24 15:09 dhanson-wp