exclude a post from wp_query loop

If I’m understanding your specific question (and posted code) correctly, you’re actually trying to exclude the most recent post from your query? If so, there’s a much easier method: use the offset parameter: $query2 = new WP_Query( array( ‘offset’ => 1 ) ); Using this method, you exclude the most recent post from $query2, and … Read more

How to retrieve the date on which a post was moved to trash?

When post is trashed, WP creates a meta field named _wp_trash_meta_time and it saves trashed time in that field. You can use that field to get trash time. Edit: Example: $args = array( ‘post_status’ => ‘trash’, ‘post_type’ => ‘post’, ‘nopaging’ => TRUE, ‘meta_query’ => array( array( ‘key’ => ‘_wp_trash_meta_time’, ‘value’ => array( strtotime(“last week”), date(‘U’) … Read more

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