Questions tagged [date-query]

Refers to a parameter passed into the WP_Query. Used to query posts by specific dates.

Filter by
Sorted by
Tagged with
0 votes
0 answers
20 views

How to add date_query to meta_query array

I am building a meta query array and all fields for the user are optional so some might not have any data. But there is also an option which requires a date query. I am still checking to see if this ...
user avatar
0 votes
1 answer
29 views

date_query empty results with custom post type

I am trying to use get_posts to return data between certain dates but I always get an empty result even though there is a lot of data. This is for a custom post type. $args = array( 'post_type'...
user avatar
1 vote
0 answers
28 views

WooCommerce Shop Orders by Date

I need to get WooCommerce orders and filter it between dates but its not working. Here's my code: $start = '2022-03-00'; $end = '2022-12-20'; $args = array( 'post_type' => 'shop_order', '...
user avatar
0 votes
0 answers
35 views

Delete all posts with a specific custom field using meta_query

I'm building a listings website using WooCommerce. A listing is either set to live or sold inside of a custom field key status Once a listing is sold then the custom field status is updated with sold. ...
user avatar
0 votes
1 answer
76 views

date_query in pre_get_posts out of memory

I'm trying to apply a Datefilter for specific categories. Wordpress crashs with a out of memory error. Is this a server problem or is my query wrong? At first I tried query -> (...) but with ...
user avatar
0 votes
1 answer
43 views

Very complex post query

I need to create a very complex post query, but I don't know if such a query can exist, or if I have to write PHP code to combine the results of two different queries... Let me please describe the ...
user avatar
0 votes
1 answer
23 views

Need to show 7 posts from actual date

I have specific category, in what I have a lot of posts. Every post starts from, for example 21 october 2019. I have this code to show posts in the correct sequence: class GoroskopController { ...
user avatar
  • 1
0 votes
1 answer
31 views

Add to previous posts under post

Goal: After each post (that contains under a certain amount of words), display the two posts that were published before it in that category/tab. I found this on stack, where they do something ...
user avatar
0 votes
1 answer
558 views

WP Query date_query with several date range

I am trying to query my post for several date ranges which are specifically posts that are published in 24 hours, within 7 days, posts that are two weeks old, and posts older than 2 weeks. I am able ...
user avatar
  • 223
0 votes
1 answer
167 views

Get posts only from current calendar week

I'm building a weekly leaderboard and trying to display posts from on the current calendar week Monday to Sunday. I've tried the code below, but it's only retrieving a post from today (Tuesday 1st ...
user avatar
  • 37
1 vote
1 answer
590 views

How to combine tax_query and date_query in Wordpress

I'm using the following query to extract all products which are not in the 'Service' product category and order them by a custom meta field '_vintage_age'. $q->set( 'tax_query', array(array( '...
user avatar
1 vote
1 answer
412 views

Limit RSS feed to previous calendar month

I want to filter my RSS feed to only show posts in the previous calendar month. I have this code in my theme functions file but it is not working? // filter the RSS feeds to show only the last ...
user avatar
  • 13
1 vote
1 answer
181 views

Date_query problems

I need to modify search query in my theme to add date_query with 'after' param based on option value from form select. Here's what I got so far: Inside form my select looks like: <select class=...
user avatar
0 votes
1 answer
222 views

If no posts exist for current day and month, show the next available day of posts

I'm writing an on this day function which should show the X number of posts for the current day and month. How can I add a fallback to the query if there are no posts, to show the next available day ...
user avatar
2 votes
1 answer
1k views

Why the 'date_query' is not working in 'pre_get_posts' hook?

I need to output popular posts in a blog using several params: Not older than one week; Rating is over than 250; Order by date Here is my code: function evanre_custom_order_query( $query ) { if ...
user avatar
1 vote
2 answers
2k views

WP_Query date_query - Use unix timestamp?

I am trying to perform a WP_Query, passing the values for before and after in the date_query as unix timestamps. This does not seem to work: $args = array( 'date_query' => array( 'before' =&...
user avatar
1 vote
1 answer
2k views

Get posts for last working week in WP_Query

With the date_query in wordpress I was trying to get posts for the last working week (Monday to Friday) I was using: $base_array = array( 'posts_per_page' => -1, 'fields' ...
user avatar
  • 279
3 votes
2 answers
2k views

Most viewed post for the last 2 days using WP_Query

Hello I have code intended to get the most viewed post for last 2 days and it seems like not working or maybe my code is just incorrect. I appreciate any help. Thanks. $args = array( 'post_type'...
user avatar
0 votes
2 answers
725 views

date_query won't accept day parameter, but will accept month and year for a custom post

I have a frustrating issue. I am using the date_query as referenced in the Codex: <?php $today = getdate(); $args = array( 'post_type' => 'Lighting', 'post_status' => 'publish'...
user avatar
  • 1
3 votes
1 answer
1k views

A WP_Query that will look for posts after 2 weeks ago OR with a certain meta value

I'm looking for a way to basically have an OR relationship between the date_query and the meta_query. Basically I want to combine the two WP_Query's. Get the posts from the last two weeks $args = ...
user avatar
  • 307
1 vote
3 answers
2k views

Get only modified posts

I'm using this code for generating a Feed from lasted modified post mysqli_query( $conn, "SELECT * FROM wp_posts WHERE post_status = 'publish' AND post_type = 'post' ...
user avatar
0 votes
1 answer
797 views

date_query is showing duplicate results

I'm trying to get the posts that was updated from today, yesterday and 2 days ago but 2 days ago is showing the result of yesterday. What seems wrong with my code? Today and Yesterday is working fine. ...
user avatar
2 votes
1 answer
3k views

Date query year and month OR just year

I am a bit stuck with setting up this date query. I am using a dropdown select box to allow the user to choose which date archive they want to view. It works for the months, but when I select the year ...
user avatar
  • 314
1 vote
2 answers
11k views

Date and Category query with filter

I am a little confused by this. I have a query that finds posts within a category and date. I can filter the categories, but I have no idea how to filter by date. The query works. I see all of the ...
user avatar
  • 314
2 votes
1 answer
5k views

Why I can't get old posts instead of recent with WP_Query?

I'm doing a WP_Query with a date_query parameter after, and I want the nearest post after that date, but I get the farest ones in the future from the date. Is there any parameter to control this? ...
user avatar
  • 651
0 votes
2 answers
6k views

Only display post if published in last 24 hours?

All I'm trying to do here is a simple custom loop using WP_Query to display posts if they are published in the last 24 hours; otherwise, a message appears telling the user to check back soon for fresh ...
user avatar
  • 135
0 votes
1 answer
84 views

Archive - Show Page Month Headers

Trying to output posts on an archive page with date titles. Ideally this can be a single query so I can paginate the archive. Currently I can call multiple queries for each date item but I don't think ...
user avatar
  • 414
1 vote
1 answer
1k views

Date Query to Pull Current and Future Posts

I'm trying to use date_query to query posts with todays date or a future date. Think events, I don't want to show any posts which has a date before todays date. I'm using pre_get_posts and setting the ...
user avatar
  • 19.6k