Articles of date query

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’ AND DATE(post_modified) > DATE(post_date) ORDER BY post_modified DESC LIMIT 50” ); and it works perfect, now I need to reproduce in a WordPress plugin and I use this code: […]

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 query like so: $query->set( ‘post_status’, array( ‘publish’, ‘future’ ) ); $query->set( ‘date_query’, array( array( ‘year’ => date( ‘Y’ […]

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’ => ‘post’, ‘meta_key’ => ‘post_views_count’, ‘orderby’ => ‘meta_value_num’, ‘date_query’ => array( array( ‘after’ => ‘2 days ago’, ) […]

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 = array( ‘post_type’ => ‘post’, ‘orderby’ => ‘date’, ‘posts_per_page’ => -1, ‘date_query’ => array( array( ‘after’ => ‘2 weeks ago’ ) […]

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 option it will only show 1 month from that year. I am also […]