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
2 answers
16 views

Send a variable with a URL and get a variable with Wp query

I want to send a variable with a url and get the value and insert that value to a variable. <a href="domain/newsletter-by-year?year=2020">GO TO THE NEWSLETTER FROM 2020</a> ang ...
kelvin ramirez's user avatar
0 votes
0 answers
146 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 ...
user8463989's user avatar
0 votes
1 answer
119 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'...
user8463989's user avatar
1 vote
1 answer
519 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', '...
Fras Jaf's user avatar
0 votes
0 answers
198 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. ...
Sven Bjorksan's user avatar
0 votes
1 answer
332 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 ...
BennyVenassi's user avatar
0 votes
1 answer
50 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 ...
Peter K.'s 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 { ...
Lestra's user avatar
  • 1
0 votes
1 answer
37 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 ...
MantaRay's user avatar
2 votes
1 answer
1k 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 ...
drifter's user avatar
  • 243
0 votes
1 answer
246 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 ...
leanda's user avatar
  • 37
1 vote
1 answer
713 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( '...
Richard Tinkler's user avatar
1 vote
1 answer
528 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 ...
Emrys's user avatar
  • 13
1 vote
1 answer
211 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=...
Andrey Vasilkovsky's user avatar
0 votes
1 answer
263 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 ...
onebitrocket's 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 ...
Eugene Zhuchenko's user avatar
1 vote
2 answers
3k 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' =&...
Luke Stevenson's user avatar
1 vote
1 answer
3k 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' ...
markb's user avatar
  • 299
3 votes
2 answers
3k 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'...
markyeoj's user avatar
0 votes
2 answers
762 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'...
C.MO's user avatar
  • 1
3 votes
1 answer
2k 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 = ...
Pete's user avatar
  • 317
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
839 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. ...
ImNotAwesome's user avatar
2 votes
1 answer
4k 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 ...
MrFox's user avatar
  • 304
1 vote
2 answers
12k 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 ...
MrFox's user avatar
  • 304
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? ...
EliasNS's user avatar
  • 702
0 votes
2 answers
7k 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 ...
la1ch3's 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 ...
ejntaylor's 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 ...
Howdy_McGee's user avatar
  • 20.5k