You’ll need to add a condition to the posts_where
filter in wordpress. I have an example here for only pulling posts that are from the current post’s date and earlier:
Add this to functions.php
// filter wp_query when $dated_before is set
function dg_dated_before($where)
{
global $wp_query, $wpdb, $dated_before;
if (isset($dated_before)):
$where = $where . " AND $wpdb->posts.post_date <= '". $dated_before . "' " ;
endif;
return $where ;
}
add_filter('posts_where', 'dg_dated_before') ;
Use this, or similar wherever it is that you are running your query:
global $dated_before;
$dated_before = $post->post_date;
$queryObject = new WP_Query();
You’ll obviously need to modify this to add the date boundaries that you need.
Related Posts:
- Pagination on archive.php page
- How to create an attachments archive with working pagination?
- Filter query_posts by tag slug on “Tag Archive” page (when tag is 2 or more words)
- How do I make archives.php for one category only?
- Query Posts Incorrectly Displaying Tags Archives
- Query Posts Creates 404 Error
- Create “archives by year and week” by category template
- How to Get All Posts with any post status?
- query_post by title?
- Order by meta value or date?
- Display posts of the last 7 days
- Filtering posts by post meta data
- How to query_posts using meta_query to orderby meta_key AND have a secondary sort by date?
- How To Modify The Loop in archives.php To Have 11 Posts Per Page and CSS Styling
- Help to condense/optimize some working code
- query_posts exclude a meta key
- Modify main WordPress loop with a parse_query filter
- How to make “sticky” pages (and query by them)
- Problem with ‘post__not_in’
- Filter archive.php by custom meta
- Sort posts alphabetically by custom field value, insert divider between different letters
- using post__in allow duplicate post id
- Use union/intersection query_posts variables in uri request parameter form?
- query_posts doesn’t order by title
- Custom query with query_posts doesn’t show post without certain meta_key
- How to sort by meta value?
- pagination in author.php template returns 404 error
- query recent posts from several categories
- Post count per (day/month/year) since blog began
- Example Query Posts Showing the Latest Post with the Featured Image
- Dynamically excluding current page id
- How do i paginate query_posts with numeric pagination?
- How to order results by date and meta key?
- posts_per_page => 1 shows 2 posts
- Show individual author rank from query of cumulative post view count for all authors
- Custom posts per page does not work with pagination
- Static Front-Page Excerpts
- posts_per_page override by default settings
- How to paginate posts correctly that belong to a particular category and are random ordered
- Tricky WP Query
- tax_query operator woes
- Possible to display posts containing a short code ?
- How to run a SQL Query for character in Post Titles
- Authors List page : how to exclude posts from certain category
- Using ajax with paging and a custom sub-query
- Duplicated posts on category page
- ACF Query meta_values don’t work with ‘offset’
- Filtering out child category posts from parent category archive not working
- How to retrieve an array of post IDs by a particular value stored in a custom meta’s array
- Query a WordPress page by its title (which has a parent page)
- define orderby URL with meta_key=post_views_count
- Query_posts and attachments
- Custom loops, sticky posts, and pagination nightmare
- Querying posts only if the current page is not paged?
- post_parent array doesn’t work
- how to store wordpress loop in array?
- meta_query check for meta value in key which holds an array of values
- Exclude posts by post meta value
- How to place an image after Nth number of posts in query_posts
- Related Posts: Notice: Undefined offset: 0
- Single-page wordpress theme navigation
- meta tag placement for google verification
- When to use WordPress loop or Foreach loop?
- Can’t get pagination to work for sticky posts only
- show x number of posts from y category on homepage
- How to Show Comment Count on Related Posts?
- How can I show only 5 posts from the relationship?
- Frontend form with multiple posts
- Way to cache a query for 24 hrs
- Make query_post category name dynamic
- How can I list posts with different formats depending on order?
- query_posts orderby postmeta [closed]
- WordPress Query based on random taxonomy
- Displaying and Querying Posts with Featured image
- View Achive with Category Filter, but Page per post not working
- Meta query stopped working
- Sticky posts don’t show up first in custom loop
- Want Page Descendants when using query_posts post_parent or child_of
- grab neighboring content in a query
- Querying a query
- How do I query based on the modified date?
- Is there any way of only retrieving posts with one or more thumbs up (GD star rating plugin)?
- My archives page won’t sort posts by month
- How to put orderby on a custom field in query_posts
- wp_remote_post and form post
- Filter posts by current date ( WP Post Carousel )
- Sort Posts By Custom Field Date
- Custom query posts error
- wp_query by last month + sort posts
- query_posts not working after wordpress 3.7 update
- Post Filter clearing on pagination $_post
- Is that the query_posts() the real criminal here?
- Query specific posts from parent by slug rather ID
- How to limit the number of posts on the home page?
- query_posts and sub pages?
- How to refine WP-Query with further criteria
- Multiple loops with / without sticky posts and different post limits
- prevent display duplicate titles on main page
- Lots of SQL queries
- Limiting the amount of posts this displays