You should probably add the filter, then use a new query, then remove the filter.
function filter_where( $where ) {
$where .= " AND post_date >= '2012-03-01' AND post_date <= '2014-03-01'";
return $where;
}
add_filter( 'posts_where', 'filter_where' );
$query = new WP_Query( array( 'post_type' => 'shop_order' ) );
while( $query->have_posts() ) : $query->the_post();
the_title();
the_content();
endwhile;
remove_filter( 'posts_where', 'filter_where' );
Related Posts:
- When should you use WP_Query vs query_posts() vs get_posts()?
- Wp get all the sub pages of the parent using wp query
- How to query for most viewed posts and show top 5
- WP_Query vs get_posts
- WordPress Custom Query to show posts from last x years
- Query Custom Meta Value with Increment
- Get posts by meta data OR title
- Perform query with meta_value date
- WP_Query ordered by custom field that is a date string?
- Pass the same object to multiple widgets in a template with one query
- Retrieve or Query Pages by ID
- How do you query wordpress posts using a math formula between multiple meta field values?
- How to implement time filter to show random post 1 month for one category and 3 months for other categories
- Page navigation doesn’t show when query category
- Meta Query for specific months
- How to query a custom post type with a taxonomy filter but display post type archive page?
- Change query_posts to WP_Query in page but does not work
- Custom Query num_rows returns wrong amount
- Slow page loads due to WordPress Core Query
- date_query seems to be ignored by wp_query
- Query Page Content From Theme Options?
- How can I override one post and make it display content for another post?
- Include current post into loop
- Filter post query to only show direct children of category
- Should I reset $wp_query?
- Show single posts date, in a page of posts
- Why doesn’t my WP Meta Query return any results?
- Filter products on category AND tag
- pre_user_query vs pre_get_posts
- Get posts that match defined arrays of tags
- Problem with my loops
- I need query_posts() to order results first by a meta value and then by post ID
- How to show post title in content editor in backend?
- My entry results are not consistently alphabetized
- Merge two queries and remove duplicate
- Ordering Posts by parent category, name ascending
- Optimising specific Query with ACF meta objects
- How to organize a WP_Query’s list of posts by category and display category title?
- When should you use WP_Query vs query_posts() vs get_posts()?
- Query custom post type by date field only working when two posts match the query
- Divide WP_Query posts by date & post type
- How to query post ids liked by the Author
- WordPress Query showing multiple titles
- custom query to get posts
- Get posts that were most recently tagged
- Modify WordPress Search
- When to use WP_query(), query_posts() and pre_get_posts
- Get post ids from WP_Query?
- Nested meta_query with multiple relation keys
- order by numeric value for meta value
- Some doubts about how the main query and the custom query works in this custom theme?
- Return only Count from a wp_query request?
- WP_Query orderby date not working
- WP Query where title begins with a specific letter
- WP_Comment_Query pagination, delving into the unknown
- Usage of the new “posts_clauses” filter in WordPress 3.1?
- Make a WP Query search match exactly the search term
- Using OR conditions in meta_query for query_posts argument
- WP_Query: query posts by ids from array?
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- Query Posts in a Predefined Order
- Sort posts by category name and title
- Order posts by ID in the given order
- How to uniquely identify queries?
- What is the most efficient way of querying posts based on visits and date for current day?
- Get Recent Posts by Date in Multisite
- Custom WP_Query order by post_meta and (author) user_meta
- Query WooCommerce orders where meta data does not exist
- Query Multiple Post types each with own meta query
- WP_Query for WooCommerce Products
- pre_get_posts with get_posts
- Get posts by menu ID
- Get the number of posts from the current page results
- author.php with ACF and CPTs
- Problem with ‘post__not_in’
- When should you use wp_reset_postdata vs wp_reset_query?
- How to know which one is the main query?
- Identify which loop you are hooking into; primary or secondary?
- Using is_main_query to select custom post type on certain page
- get query’s query string
- Meta Query with date and time on the same Day before given time
- get_the_title($postID) OR get_the_title()?
- How to make an activities stream mixing posts and comments?
- Duplicate Queries
- How to query for a week using key => value WP_Query argument notation?
- Display Posts by modifying the where clause only for my query
- Finding all results from database within 500 miles of the given latitude and longitude [closed]
- Show only oldest post by author
- Order posts by tags count?
- SQL query equivalent to WP User Query
- How do I create my own nested meta_query using posts_where / posts_join?
- Add and in the header while looping over custom query in page template
- How to get the posts published in last two days using WP_Query?
- Highlighting Sub topic in a post?
- How to use filter hook posts_join for querying taxonomy terms in posts_where?
- Best practice for multiple queries on page
- Which custom query am I in and how can I access its properties & methods?
- How to count post type that has a particular term?
- How to Get All Posts but the Private ones?
- Finding the next 5 posts