Skip to content

Provide a way to query for posts before or after a specific time (not just date) #1234

Description

@kellenmace

In my app, I need the ability to fire off a request every few minutes to the WP backend to get any posts that have beed added or edited since the last time I checked. Currently though, WPGraphQL only supports doing date queries using day, month and year. You can't get more specific than that and narrow it down to a certain hour/minute/second. Example:

query getPosts {
  posts(
    first: 10,
    where: {
      dateQuery: {
        column: MODIFIED
        after: {
          # Need to add hour, minute & second here.
          day: 13
          month: 4
          year: 2020
        }
      }
    }
  ) {
    nodes {
      postId
      modifiedGmt
    }
  }
}

WP_Query() does provide that ability by accepting a strtotime() compatible string as the before/after argument. Documentation: https://developer.wordpress.org/reference/classes/wp_query/#date-parameters

Even if we want to avoid accepting an arbitrary string like WP_Query() does, I think this can still be accomplished by accepting hour, minute, and second input args for before and after. Then apps like mine that need to query for published/modified posts on a frequent interval would be able to do so.

Who's with me?

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: inputRelating to GraphQL Input Typescomponent: queryRelating to GraphQL Querieseffort: lowAround a day or lesshas: workaroundA temporary workaround has been providedimpact: medMinor performance improvements, fix broad user base issuesobject type: postRelating to the Post Object Typesscope: apiIssues related to access functions, actions, and filtersstatus: actionableReady for work to begintype: enhancementImprovements to existing functionality

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    ✅ Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions