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
- WP_Query orderby date not working
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- Query Posts in a Predefined Order
- How to uniquely identify queries?
- Problem with ‘post__not_in’
- How to query for a week using key => value WP_Query argument notation?
- SQL query equivalent to WP User Query
- How to use filter hook posts_join for querying taxonomy terms in posts_where?
- meta_query on a date range using an array of values
- How to detect custom query inside `posts_where` hook?
- Is temporarily overwriting $wp_query a bad idea?
- How to Loop within a Loop (Display Children and then Grandchildren)
- How to output different posts per page?
- Query post with meta_query where date is not in future
- merge two query arguments into one WP_Query call
- Using WP_Query in “parse_query” or “pre_get_post” in Posts2Posts
- How to reduce the number of queries?
- Comparing dates in custom field
- WP_Query last five posts, simply ordered by meta_value
- WP_Query “OR”: Find posts by ID, Name or Post Title?
- WP_Query condition affects posts_per_page count
- Weird orderby => post__in issue
- Set global $wp_query/$post variable for dynamic page generation
- Meta Query relation “AND” then set array accordingly
- posts_per_page option limits the number of Gallery items
- WP Group posts by year(desc) > month(desc) > date(asc)
- Is there a better way to pull in custom content without querying posts?
- Reset WordPress Post Query to default
- Query posts that contain video?
- Show a 404 error page if Public query variable’s value doesn’t exist?
- Set front_page programatically after user login via query, while leaving site option alone
- Filtering posts by archive showing all years
- How to give classname to post if post has no content?
- mysql query order by
- Notice thrown when creating numeric pagination on custom query
- Creating attachments archive in tags and categories
- Posts limit on homepage (genesis framework)
- How do i create a custom post query when the meta value is an array?
- How to do WP_User_Query for Nested Array value Inside Nested Array field
- Custom query to retrieve oldest post and retrieve others with date interval
- Sorting query_posts() with a complex orderby filter
- How to query 5 users in random who have published more than 10 posts
- Slow wp_posts and wp_postmeta query using Advance Custom Fields
- What is the best way to reset a search on a meta_key / meta_value?
- Pull posts from all categories if quantity is not met?
- Query_post 5 post first / last of post_id
- Bring a post to the top of the query if it’s in a certain category?
- WP_Query with child element
- Sort / Filter Queries
- Using WP_Query to re-query and sort results using a date?
- Pagination is not working on custom query inside a custom home page template
- Converting an existing query_posts to WP_Query
- Showing posts from 4 categories along with all latest posts
- Help in query for list links
- WordPress pagination returns the same posts