You can’t really check post_date
in pre_get_posts
, because, well, the action fires before (pre_
…) the posts have actually been fetched (…get_posts
). 🙂
But, you can use $query->set()
to add date parameters to the query. This is taken from an example in the WP_Query()
Codex entry:
<?php
function wpse54142_filter_pre_get_posts( $query ) {
if ( is_feed() ) {
$today = getdate();
$query->set( 'year', $today['year'] );
$query->set( 'monthnum', $today['mon'] );
$query->set( 'day', $today['mday'] );
}
return $query;
}
add_filter( 'pre_get_posts', 'wpse54142_filter_pre_get_posts' );
?>
Related Posts:
- Sort on meta value but include posts that don’t have one
- multiple orderby in pre_get_posts action
- How to alter query order direction using $query->set(‘order’, ‘ASC’); inside a pre_get_posts filter?
- Use pre_get_posts to sort meta_key by an array of values
- Why does pre_get_posts() return “date” as the orderby parameter for every sortable column?
- pre_get_posts shows posts in random order sometimes
- Sort by DESC works, ASC doesn’t?
- Sort posts by meta value with get method
- How to order posts by parents?
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- How to Change Order of Posts in Admin?
- WP_Query orderby date not working
- get_the_terms in descending alphabetical order
- next and previous post link ordered alphabetically
- How to put last edited entry on top of the blog-post list?
- Order posts by meta_value even if meta_key is not filled
- Order by first name
- Query posts from current year
- Meta query interfering with orderby relevance
- Order posts by (hierarchical custom) taxonomy terms and term children
- Arrange Posts By Date In Order Of Closest To The Current Date
- Retrieve taxonomy terms in order of their post’s date?
- Sorting Attributes order when using get_the_terms
- Filter query posts by the count of metas for a meta key
- How to order posts by meta value?
- Display custom post types by date field
- How to order posts (woocommerce products) alphabetically but ignore certain words, eg ‘The’ and ‘An’
- Ordering by meta_value AND date NOT WORKING with wp_query
- Ordering system through WordPress
- pre_get_posts order by not working
- Arrange posts by date in front page
- Issue with multiple orderby values
- pre_get_posts query between 2 dates (date stored in custom post meta)
- get_query_var returns wrong default value
- Complex WP_Query order request: DESC by day, but then ASC by time
- Show first the posts from 1 specific tag
- All, published and pending order
- Ordering posts by publish date not working?
- WP_Query: Group events by year, sorted DESC; then by date for each year group, sorted ASC
- Get_Users Orderby Page
- Sort order of next/prev sibling page
- Help ordering Post loop by two meta values
- Order ascending is ignored in meta query?
- Order char by post title
- next_post_link and previous_post_link order not working properly
- query pages by a childs publish date
- Sorting a query Field by date
- WordPress Screwing Up ‘orderby’ => ‘meta_value_num’ in ‘pre_get_posts’
- Ordering posts by custom field named “date” in backend
- List most recently added posts (with a twist)
- WP Query – order posts by meta field first and then order the rest
- Featured-Content/Featured Posts With Random Order
- Orderby in Query Posts affected by operating system?
- Ordering posts by title containing numbers
- Stylesheet Enqueue Order and Best Practices
- How to display taxonomy terms the way they are hierarchical
- Child pages not affected by orderby
- Order by ASC, DESC, Title, Date from URL on custom page template post
- Offset posts with random order
- view subcategories order by id
- Sort query output on taxonomy term archive by post type using pre_get_posts
- Order posts by date
- ASC and DESC separately from orderby
- How to query posts by month based on date custom field?
- struggling to order by title
- Order by two meta values – one is a number and the other is text
- Order posts by taxonomy terms
- Order column custom date using pre_get_posts
- Shop sends Mail with order cancellation
- List of terms in alphabetical order under the respective initial letter and within columns
- Random order not working correctly when using default loop + $query->set
- Changing cache update rate
- Multiple orderby date arguments
- WordPress Admin – Automatically Sort Custom Posts by Custom Field Date Value in d-m-Y Fomat
- how to complete order status automatically after paypal payment received
- Order management including recurring orders on woocommerce
- Orderby Title not working
- Sort loop by title doesn’t sort single digits like human would
- What’s the most efficient way to get two queries based on an if statement?
- How to order custom user list columns by datetime?
- Creating a post that contains a list of other posts like a table of contents
- Changing posts order on a page
- Re-order posts inside tax query
- Pre_Get_Posts order DESC not registering
- Ordering Subcategories
- single post navigation order (NOT chronological)
- Problem with meta_value order after update
- Last three posts not being put in order by date. How to fix this?
- Random order of posts on each request
- How can I make have_posts() return posts ordered DESC by id?
- Add post order like page order
- Woocommerce Pre Orders view order link wrong [closed]
- Orderby with menu_order and title
- Sort wordpress posts by facebook likes [closed]
- Get posts that were most recently tagged
- Order Wp Query by earliest of 3 dates meta query
- How to use orderby on meta_value when using Pods custom database table storage
- Sorting by date not working?
- How to put posts with some taxonomy on top of others in `pre_get_posts`
- WP_Query sort by ACF date field (newest first) with blank dates first