WP_Query date filter for a day
-
Hello,
i added a function to get the count of post for a day.
Here’s the code :
if ( ! function_exists( 'mysite_get_post_count_by_date' ) ) : /** * Return post count for a date. * * @since mysite 1.0 * */ function mysite_get_post_count_by_date( $year, $month, $day = '' ) { if ( ! empty ( $day ) ) { $args = array( 'date_query' => array( array( 'year' => (int)$year, 'month' => (int)$month, 'day' => (int)$day, ), ), ); } else { $args = array( 'date_query' => array( array( 'year' => (int)$year, 'month' => (int)$month, ), ), ); } $search = new WP_Query( $args ); if ( ! isset( $search->post_count ) ) return false; $count = $search->post_count; wp_reset_query(); if ($count < 1) return false; return true; } endif;
If i check this function, it always return all posts of the blog and not only the posts of the day. It seems the date_query args doesn’t work and i don’t understand why.
Thank you for your help !
Kind regards
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘WP_Query date filter for a day’ is closed to new replies.