Make WordPress Core

Opened 8 years ago

Last modified 2 years ago

#38641 new enhancement

Support partial ISO8601 dates in queries

Reported by: rmccue's profile rmccue Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 4.7
Component: REST API Keywords:
Focuses: Cc:

Description

Right now, we support sending date or modified with a full ISO 8601 date (yyyy-mm-ddThh:ii:ssZ), and we also support before and after. However, there's no easy way to get posts for a certain month, without building the before and after yourself.

ISO 8601 gives us a way to specify partial dates: yyyy and yyyy-mm are both valid, and we could totally support them. This avoids the need for a separate year or month query parameter. Internally, this can map to before and after values.

Change History (8)

#1 follow-up: @joehoyle
8 years ago

Internally, this can map to before and after values.

If these go to before and after values, does that mean that ?date=2014 returns all posts after 2014? I presume someone would mean "only get posts from 2014" with that?

#2 in reply to: ↑ 1 @rmccue
8 years ago

Replying to joehoyle:

If these go to before and after values, does that mean that ?date=2014 returns all posts after 2014? I presume someone would mean "only get posts from 2014" with that?

Note: "and"

date=2014 would map to after=2013-12-31T23:59:59&before=2015-01-01T00:00:00

#3 @kadamwhite
8 years ago

I like this idea a lot; it's a much more elegant way to find a specific time period than passing two full ISO date strings with tailored T values just to get a month or a day of content

#4 @rmccue
8 years ago

  • Keywords 4.8-early added
  • Milestone changed from Awaiting Review to Future Release

Punting to 4.8.

This ticket was mentioned in Slack in #core-restapi by jnylen. View the logs.


7 years ago

#6 @LaustDeleuran
7 years ago

#38986 was marked as a duplicate.

#7 @LaustDeleuran
6 years ago

Reacting late to @jnylen0's request to repost my issue from #38986 here. Basically, the documentation implies full ISO 8601 compliance, but the API only works when you include a full date and time, ie. YYYY-MM-DDTHH:MM:SS. For instance, this fails, even though I'm passing a valid ISO 8601 date:
http://demo.wp-api.org/wp-json/wp/v2/posts?before=2016-11-29

The documentation should either specify the specific format that the before/after parameters require, or support full ISO 8601. In my opinion, the latter would be preferred.

Thanks.

#8 @johnbillion
2 years ago

  • Keywords 4.8-early removed
Note: See TracTickets for help on using tickets.