We’re rewarding the question askers & reputations are being recalculated! Read more.

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
0answers
14 views

pagination on wordpress and not showing all results

I have this page that shows posts from a range of years selected of a form on a previous page. the first results display the 10 posts as set in args(post_by_page => 10); if there are more posts I ...
0
votes
1answer
27 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 ...
0
votes
1answer
31 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 ...
0
votes
1answer
71 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 ...
1
vote
1answer
285 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( '...
1
vote
1answer
107 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 ...
1
vote
1answer
90 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=...
0
votes
1answer
83 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 ...
0
votes
1answer
678 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 ...
0
votes
2answers
1k 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' =&...
1
vote
1answer
914 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' ...
2
votes
2answers
1k 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'...
0
votes
2answers
317 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'...
2
votes
1answer
841 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 = ...
1
vote
3answers
1k 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' ...
0
votes
1answer
577 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. ...
2
votes
1answer
2k 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 ...
0
votes
1answer
8k 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 ...
2
votes
1answer
4k 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? ...
0
votes
2answers
4k 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 ...
0
votes
1answer
73 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 ...
1
vote
1answer
818 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 ...