Very complex post query

I got inspired in solving my problem by this thread! The idea is to create individual queries (unordered to save time, as sorting is not needed at this stage) to get the post IDs that meet your criteria; then take those IDs and run a final query with the IDs as the criteria to get … Read more

Only display post if published in last 24 hours?

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’ ) ) );

Date_query problems

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 … Read more

Limit RSS feed to previous calendar month

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, ], [ … Read more

Date and Category query with filter

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 … Read more

Get posts for last working week in WP_Query

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( ‘previous week Friday’ ) ) ); $base = get_posts($base_array); I’ve not tested it. But I tested that below code returns the perfect … Read more