12% off of LTD using this coupon: TWELVEPERCENTOFF. Promo ends on 2 Dec midnight UTC.
Published on Mar 4, 2021

date_query with pre_get_posts in Oxygen

Sridhar Katakam

In the WPDevDesign Facebook group a user asks:

Quick question to smarter minds. I need to create a easypost/ repeater query where I show a set of custom posts created in the last 3 months. e.g. we get donations online, and each payment is a post of a custom type. I know how to query for a fixed number, but how do I do 'in the last 3 months'?

This members-only tutorial provides the steps to filter the posts output by Oxygen's Easy Posts or Repeater component so it fetches only the entries that have been published in the last 3 months.

Note: This is for secondary queries. For the main query, the logic is the same but the implementation differs slightly in that you would pre_get_posts in a Code Block or a custom functionality plugin.

Step 1

Edit your Page/Template with Oxygen.

Add an Easy Posts or Repeater inside a Section. Let's go with my personal preference, Easy Posts.

Set the WP Query to custom and select your desired post type and Count.

Tip: If you wish to show all the items, set a high number for count like 100 or something that will always be higher than the number of posts that are possibly present rather than tick All.

Step 2

Add a Code Block component and move it above the Easy Posts.


This is a premium members-only content.

To view the rest of the content, please sign up for membership ($47/month or $599 one-time).

Already a member? Log in below or here.