This should work:
$query->set( 'date_query', array(
'relation' => 'OR',
array(
'column' => 'post_date',
'after' => '-7 days'
),
array(
'column' => 'post_modified',
'after' => '-7 days'
)
) );
You might want to adjust the callback’s name, since it’s not only ordering the home page. You also have _asc
in that name but are setting the order to DESC within it. So it might cause confusion.
Note that you will not have accessible permalinks for the future posts.
It might be more flexible to filter the posts on the home page according to some category/tag/custom-taxonomy instead of excluding hardcoded post IDs.
Related Posts:
- ajax category filter
- WordPress 4.9.5 PHP intermittent warning trim() expects parameter 1 to be string, array given
- Pagination custom query
- Order by two meta keys
- Finding all results from database within 500 miles of the given latitude and longitude [closed]
- Function to check if author has posted within the last x days
- Shortcode returns escaped HTML tags
- Calling a custom excerpt function in a local loop
- How to get any tag ID
- Dynamically Override Fancy Title – Part II
- query posts in functions.php and update a field
- Get posts using WP_Query
- Finding post content that begins with a specific character
- Best practice custom function, where to echo the variables?
- How to get user_id from wordpress database inside ajax function?
- posts_per_page not working
- Exclude admin from WP_Query Contributors
- Multiple Loops Inside a Function
- How to delete taxonomy term when a wordpress user is removed?
- Exclude category for main query and custom
- Display posts from only one post form in custom query and exclude in main query
- Category applied to pages, creates multiple breadcrumb entries after a search query (On the translated site)
- How to filter, restrict and return posts based on custom user meta information
- WP Query using tax_query & meta_query
- wordpress search word, “hello world” ===> ‘hello+world’ ===> ‘hello’, ‘world’
- Display most popular in the past two days
- meta_query not working as expected
- New WP_Query calls Pre_get_posts filter twice
- how to access query string in wordpress?
- Merge two search functions for custom post type
- Make a SQL query with wpdb in WordPress
- how to use pre_gets_posts to exclude one queried ID from homepage loop
- Error with function in functions.php?
- Exclude authors IDs from WP_Query
- Loading two different AJAX requests on two different pages
- Getting the post terms ‘wp_get_post_terms’ per post when within the functions.php file
- How to load a script code only in posts?
- Multiple meta_key ordering with pre_get_posts
- Create a notification for post field
- Add URL Rewrite Rule To WordPress
- Trying to get property of non-object in: $wp_query
- WordPress dynamic AJAX query
- relation OR instead of AND – Filtered term ID’s in loop
- Pagination repeating posts on search results
- How to check if logged in user have pending custom post?
- Custom WordPress post query for displaying time-released content on website
- SEARCH QUERY PLEASE HELP | call_user_func_array() expects parameter 1 to be a valid callback php
- Custom query for custom post type not getting correct post ID
- Finding post ID dynamically on click
- how to move a page from one drop down menu to another drop down menu
- How to upload 3 attachments to current post?
- Global page ID variable empty error
- WP_Query & shortcode : Return 3 articles from a category WordPress
- Get post Number with local loop and template
- Save query in function for custom gallery
- Seach and categories not working when ignoring sticky posts in main loop
- Problem with custom WP_Query and underlying pagination/posts_per_page
- Calling a function with WP_Query only ever brings the first result
- What argument does my function need to echo get_results() query results
- Fetching $_POST from Page Template into functions.php
- Declare inline background image in functions.php
- I wan to process the following js to process the AJAX Request on my function to calculate author Total Post views
- Hiding all posts/products/pages from a site based on a custom taxonomy/domain name
- ordering and optimizing functions
- Why WP_Query in functions.php is not working when get_posts works?
- Adding css tweak based on page template
- WP_Query and DES sort for Custom Taxonomy based upon a meta field?
- How to write a query-function as a query-shortcode?
- 1500+ duplicate queries via get_option function (query monitor)
- Variations as Single Products [closed]
- Excluding a category from frontpage but not from WP_Query
- When tax_query used, results disappear (0 =1 produced)
- How to get Page/Post Gallery attachment images in order they are set in backend using WP_Query()?
- What exactly does the ‘s’ parameter search for in WP queries?
- get_posts not finding argument: post_name
- get query’s query string
- Show only oldest post by author
- Modify existing query and change order of posts
- Why does the_content not work like others for a set post id?
- How would I format a query that depends on post parent taxonomy
- WP_Query Group by Author and Order each group DESC
- List only posts from specific category on category page
- WP_Query() order by post content lenght?
- reset to main loop doesnt work
- WP_Query with rewind_posts creates duplicate titles
- Get a list of ACF Repeater-Fields as array
- Show single posts date, in a page of posts
- Compare “Main” post ID to ID inside wp_query loop
- Attempt to display site authors in a carousel – User Image not Outputting inside li tags
- problem with the loop
- Facing problem with tax_query results
- sanitize_post() is not sanitizing Post Object
- Unusual high query of user meta data
- Woocommerce featured products query no longer working
- Custom WP_query and integrating into theme file
- Why does order ASC break offset in WP_Query?
- new WP_query using custom fields
- Having Trouble Running Query From Shortcode Using Tribe’s Events Plugin
- Change ‘post_modify’ with a query
- shortcode with $atts with strange results