have you tried adding a second $query->set() ?
function loop_current_month( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'monthnum', date('m') );
$query->set( 'year', date("Y") );
}
}
add_action( 'pre_get_posts', 'loop_current_month' );
This should get all the posts from the current month or this year, note date(‘m’) and date(‘Y’)
Related Posts:
- Insert/sticky specific post into Loop at specific location
- Two loops by pre_get_post on same page
- Make blog page show 10 on first page, 9 on every other page
- Exclude posts from main loop based on meta value
- Alter query using pre_get_posts() if meta_key is present
- pre_get_posts for two loops on same page
- Sanitize Custom Field Value in Meta Query
- Change post order by meta key, per post basis
- Exclude Posts Using Meta Query and User Meta
- pre_get_posts main_query not displaying after applying tax_query filters
- Query counting excluded category on paged loop
- Get query result before posts are displayed?
- How to use orderby on meta_value when using Pods custom database table storage
- if ( is_home() && ! is_front_page() )
- How can i display the content in plaintext
- Why am I being limited to ten posts on a custom loop?
- Child Pages Loop
- Loop.php vs looping inside template file
- “pre_get_posts” firing on every query
- Style every four posts differently [duplicate]
- Return vs Echo Shortcode
- have_posts() return false but count says “3”
- next_posts_link not working in custom loop
- Ajax loop in sidebar to load post titles/categories
- How to sort posts in archive loop
- wordpress post loop in javascript
- How to iterate through database until it find a match
- Show top level comments ordered by number of replies
- Redirect Loop to Page, Can’t Find Origin, Can’t Remove [closed]
- Loop through pages with specific template
- Loop starts from the beginning with second while loop on author.php
- wordpress change the loop order by dynamic value
- Post Format single-loop.php using get_template_part
- Single page site (WordPress) including posts
- Meta Query with spaces in value?
- A loop with all articles with certain text strings in tags
- Prevent Headers from being sent
- How do I get row padding in a post feed?
- How can I create a legend (Key) like the one in the footer on WordPress StackExchange
- It is possible to encounter horrible bugs if I place a main loop that uses `query_posts` right above the main bbPress loop?
- Styling text and images in the_content()
- How do I use AJAX Query in my posts loop?
- How to show “teaser” posts on blog / archive pages, otherwise full posts
- Output loop leveraged shortcode twice on one page
- Next Posts Prev Posts for Standard post format only
- Two loops on different pages do the same thing, but only one page works
- Posts active and expired in different loops
- Genesis multiple category custom loop 404s after first page
- Shortcode in posts called by ajax is not working
- Latest Post Styled Different Than other Posts
- ACF custom field in [closed]
- Split wordpress loop to multiple layouts
- WordPress: Loop Help
- Woocommerce: How to display product price [closed]
- Update status of all posts in a category
- Loop counter style
- Can I add generic numbering HTML classes to items as a loop runs?
- Add “showing posts x to x of y” in custom post type paginated loop
- Custom Post Type on Homepage – Studiopress Genesis Framework
- New loop vs widget
- Display a single category in blog section
- Query Nopaging action not having effect
- Yoast taking over my WordPress title tag [closed]
- Pagination broken after using 2 loops to show content
- Getting page slug
- How to get pagination to work with 2 wordpress loops
- Exclude page from loop results
- How is WordPress changing the content markup?
- Inserting CPT and static content at every X post, is this possible?
- loop through posts and display inserted media and post title as a link
- using update_user_meta to rank users
- Custom Blog Loop on Home Page
- Exceprt not displaying
- Add File Attachment Name and URL into Javascript
- Open Graph in Index Loop
- How to tell if all posts are only in one category?
- How do I set the Stewart Search Template to return only published posts in the result
- Updating Post meta (ACF field) from Feed
- How to add pagination in Terms
- A code that I could not fully grasp related to foreach & count_user_posts()
- How to separate post titles with a comma in the loop?
- get_posts changes main query
- Trying to get property ‘post_content’ of non-object
- WordPress loop : how to exclude some posts with their status?
- Homepage Loop Somehow Breaks Styling Of Post Grid
- Foundation modal in wordpress php loop
- Next 10 posts data of currently viewing post in blog page
- Have multiple loops on a page appear after/between page content
- How to fix pagination for custom loops?
- WordPress Multiple Loop: Home/Archives Page, with pagination
- Placing the content of one post in two side by side columns, newspaper style
- trying to write a variable into a wp_query, need help!
- Pass WP post content to a jQuery plugin (Fancybox)
- Showposts doesn’t show the number of posts indicated
- Using in_category for non standard loops
- Use Loop or direct database query?
- How wp maps urls into files
- Display Featured Image
- AJAX in wordpress theme loop
- Duplicate post problem