How to filter a query by date in a shortcode?

Note that you’re returning from the shortcode’s callback with: return $pops_content; before removing the filter’s callback with: remove_filter(‘posts_where’, ‘filter_where’); So it’s never called. That means you’re affecting all the later WP_Query instances with your filter. Note that you can use date_query in WP_Query instead, so you don’t need the posts_where filtering.

Shouldn’t I be able to modify the main query by this filter?

The reason your code isn’t working is because by the time archive.php runs, the pre_get_posts hook has already fired. You can easily accomplish the task in your functions.php file: add_action( ‘pre_get_posts’, ‘wpse_pre_get_posts’ ); function wpse_pre_get_posts( $query ) { remove_action( ‘pre_get_posts’, ‘wpse_pre_get_posts’ ); //* $query->have_posts() will always return false from this hook //* So get the … Read more

WP_Query Limit Data_Query last 90 days

In order to query posts with a date_query, you can pass the argument of column post_date_gmt which is the date the post was published, and then pass the argument of before/after and a string to represent your request. So for published posts from now until 90 days ago, you would put this in your WP_Query … Read more