Contentful logo

Contentful Community

Date range filter using relational query

On our website we’re trying to hide / show published content modules on a page according to a date range. We have a ‘page’ content-type that has a field link reference to a ‘visibilityWrapper’. This ‘visibilityWrapper’ content-type has link references to the published content that we want to hide / show, along with ‘showAt’ and ‘hideAt’ fields of datetime type. Is it possible to use the CDN API to filter out the page’s visibilityWrapper field (from the returned page’s fields in the items array and also from the includes array) if the visibilityWrapper’s showAt and hideAt range is outside a particular date parameter?

We were looking at using relational queries for example:[lte]=2019-01-17T11:35:31.157550&fields.visibilityModule.fields.hideAt[gte]=2019-01-17T11:35:31.157550

However this brings back no results when the time is outside the showAt/hideAt range. What we want is the page (fields.url=test-visibility-page) returned MINUS the page’s field of type visibiltyWrapper when the wrapper’s showAt / hideAt range is outside the desired date. Is this possible with the CDN API?

This might be something like using the ‘select’ operator but with a conditional attached, i.e., only include this field when date is within the showAt /hideAt range.