5

As birgire said date query is an array of arrays May be this solves your problemo. $args = array( 'post_type' => 'surf_reports', 'posts_per_page' => '1', 'category_name' => $cat (this is pulled dynamically in my template), 'date_query' => array( array( 'after' => '24 hours ago' ) ) );


4

You have not stated how the selection works, but you need to have some kind of conditional set when a specific month is selected and when a year archive is selected. I also do not know where get_the_time comes in or its relevance to the query. But anyways, there are some other really big issues that I would like to discuss as well. You are using non-...


3

Are you actually using 'after' => date('Y-m-d h:i',time()) in your code? That will always ask for posts older newer that the exact current time when that query is run. Something like this: 'after' => date( 'Y-m-d h:i', time() - 60 * 60 * 24 ) would give you a reference for 24 hours in the past. The above part is for history's sake. The solution in ...


3

I wonder if you mean this kind of date_query: $query->set( 'date_query', [ [ 'after' => 'today midnight', 'column' => 'post_date_gmt', 'inclusive' => true, ], ] ); where we use the after attribute. Here the after date will be calculated by WP_Date_Query as: gmdate( 'Y-m-d H:i:s', strtotime( 'today ...


2

It might be possible to achieve this by using the post clauses filters and rewriting the generated SQL query. You can also run 3 queries, One very lean query to get the desired posts from the date_query One very lean query to get all the posts from the meta_query One final query to get the complete query object. This help specially with pagination if you ...


2

You can use the posts_where filter: // Add custom filter add_filter( 'posts_where', 'wpse_modified' ); // Fetch posts $query = new WP_Query( $lastupdated_args ); where you can define the filter callback as: function wpse_modified( $where ) { global $wpdb; // Run only once: remove_filter( current_filter(), __FUNCTION__ ); // Append custom SQL ...


2

You've got trailing space in your $query->set(). Instead of $query->set( 'date_query ', ... it should be: $query->set( 'date_query', ...


2

I'm afraid that there is no way to do such advanced queries using WP_Query. But, of course, you can still achieve that result, but you'll need to write a little bit more code. There are two solutions: It's hard to give you precise code, because there aren't many details in your question, but maybe this will be enough :) 1. Use posts_where and posts_join ...


1

Try to add date_query to the $qry in the solution mentioned here. $qry = new WP_Query( array( 'cat' => $current_post_categories[0], 'posts_per_page' => 2, 'post__not_in' => array( $current_post_id ), 'date_query' => array( array( ...


1

This approach doesn't work for January: $lastMonthNumber = date( 'n', current_time( 'timestamp' ) ) - 1; as it would give 1 - 1 = 0. Here's another suggestion, using the string to time support of the date query: $query->set( 'date_query', [ [ 'after' => 'midnight first day of last month', 'inclusive' => true, ], ...


1

Since your code returns the posts belonging to 5 years ago, then I assume your problem is in the conditionals, since none of them are run. The form elements must have a name if you want to get their values in the back-end. Your select lacks a name, and you are trying to get its value by using its ID. You should use it this way instead: <select class="...


1

How to solve this depends very much how you store it. In general I would be aware of letting WordPress handle historical dates, of broad range, as post dates. There are various limitations that you can check on this site or eg. trac. Date query for yesterday If you create a datetime object with: $dto = DateTime::createFromFormat( 'Y-n-j', current_time( '...


1

Well, try the below code- $base_array = array( 'posts_per_page' => -1, 'fields' => 'ids', 'post_type' => 'cpt', 'post_status' => array('publish'), 'date_query' => array( 'after' => strtotime( 'previous week Monday' ), 'before' => strtotime( '...


1

I had the same issue. I had searched many times for this issue. but I could not find a solution for this. get the most viewed post for the last 2 days not to get the posts for the last 2 days I have a table named "wp_popularpostssummary". Result ll be so from this table get result postids by using following custom query $results = $wpdb->...


1

As I said in comments, you can do this in one query by making use of the relative time and date functionality in PHP which is also vailable in a date_query. You simply need to pass something like 2 days ago to the after parameter in the date_query to get posts from today, yesterday and two days ago. Just remember to sort your posts by modified You can try ...


1

I was going about this the wrong way around. I needed to allow the user to select the date first and then the category. I also needed to make the dropdown boxes auto select, so that the date search is performed first taking the user to the date archive and then the user can select the category they require. <form class="my-filter" method="GET" action=""&...


Only top voted, non community-wiki answers of a minimum length are eligible