I was afraid you wanted that one. You can’t really do that. Follow the link for some workarounds. You could also set a variable or a constant in functions.php
, or create a theme option for this. Then use that in your function.
function smbd_cats_by_days ($where="") {
// global $days_limit; // if a variable
// $days_limit = DAYS_LIMIT; // if a constant
// $days_limit = get_option('days_limit',100);
// you have to uncomment one of the above,
// depending on your choice of mechanisms
$where .= " AND post_date < '" . date('y-m-d', strtotime("-{$days_limit} days")) . "'";
return $where;
}
add_filter('posts_where', 'smbd_cats_by_days');
Related Posts:
- How to limit search to first letter of title?
- WordPress Search Filter Only for Page with Child of Child of Child of Child of Child
- Problem with ‘post__not_in’
- Sort X categories by last update and show image
- using post__in allow duplicate post id
- Counter code for paginated category pages in wordpress
- pagination in author.php template returns 404 error
- How to modify the query to exclude posts by slug?
- How to implement time filter to show random post 1 month for one category and 3 months for other categories
- Querying posts with meta value that begins with a certain pattern
- Adding Variables to post query
- Tricky WP Query
- query_posts() ALWAYS displays something?
- Using ajax with paging and a custom sub-query
- Get Posts updated or published within the last x hours
- define orderby URL with meta_key=post_views_count
- How to remove a plugin filter’s priority on specific loops (custom queries)?
- Each post is showing twice in my custom query…?
- Filter post query to only show direct children of category
- Exclude posts by post meta value
- Currently using a query_posts() in my theme – want to use a request filter in stead
- Can I use WP_Query one time and then filter the results multiple times
- Different layout based on post amount?
- How to solve this without flushing the rewrite rules for each post query the visitor triggers?
- How to check a list or feed of all posts under a category and tag?
- Best Query for blog posts
- Pre-existing arguments when using queries
- Adding Category Argument into an Array for WordPress Query
- posts_per_page no limit
- Get the ID of the latest post
- How to modify posts_where filter only for the search query
- Query posts by custom taxonomy ID
- What is the most efficient way of querying posts based on visits and date for current day?
- Query posts: how to exclude results if post is in multiple categories
- Custom query incorrectly returning everything [closed]
- query_posts ->using meta_compare / where meta value is smaller or greater or equals
- Alter query on edit.php
- WP 5.8 “Query Loop” block: where to place custom query?
- Pagination on archive.php page
- order post my meta value m/d/y format with year as included value
- _wp_page_template to dynamically use template
- Total Count of Posts NOT in Selected Categories?
- How to display liked posts of current user in wordpress?
- Used with meta_query in query_posts works slowly
- Using database meta_values to calculate new post order using pre_get_posts or a ‘request’ hook
- exclude ids through post__not_in
- Page navigation doesn’t show when query category
- post_status => publish not working
- How to fetch all posts in a category that were published between two given dates?
- Modifying date filter on admin page for custom post type to link to custom field
- get_meta_data within a loop
- how to exclude “featured” posts from the main loop?
- Filter custom posts with / without comments
- pass query string on url to filter media
- Order posts by condition
- Co-authors plus problems with query_post
- Error sending array of inputs
- Query last updated posts (posts updated in the last 24 hours)
- order posts by meta value on posts page
- Search breaks when querying main loop for category
- How to use the query hook/filter?
- Adding conditional content to single post-type template
- Query posts by meta_key whose value is an array
- using query_posts to pull posts out of a category in a while loop. Getting odd echo
- Echo a numerical value in query_posts
- Breadcrumbs stop working on a specific template file
- Custom search SQL Query to add custom field in result
- Order for custom field after the loop
- Custom post query error
- Why doesn’t my WP Meta Query return any results?
- Multiple instances of query_posts
- If Query Post Returns 1 Post
- Keeping get_posts’ offset and is_paged() synchronized
- odd behaviours from template tags
- How to get any type posts include attachments by ids?
- Create a Loop with Posts Ordered by Most Recent Comments
- Filter products on category AND tag
- Query filter by value in meta_value array
- Specifying image size used in template the_content
- Add option to query string before get_posts() is called on archive.php
- allow user to edit posts made by others users based on the user role
- Admin view: filter posts by whether they have specific taxonomy attached
- Sort Events by Venue Title – Sort Post set by related post ids
- Optimising specific Query with ACF meta objects
- Order posts by ACF checkbox
- Post per page not working
- Show previous month’s posts
- query_posts result differs from wp_query request result
- If meta_key has value = 6 | Change the wp_posts.post_date to current date
- Query Posts by date range with fixed beginning and end
- Collect posts from last 48 hours
- How to go to tag archives using a form
- WordPress loop problem: Multiple loops, index.php and is_paged causing duplicate posts on next page
- Why doesn’t this page query work?
- Resetting a Query using wp_reset_query() or wp_reset_postdata() does not work
- Sort posts with multiple meta_keys
- Create “archives by year and week” by category template
- Query Multiple Filters, one with Meta
- Sort Posts Alphabetically Based on Specific Category (Divi)
- Custom Filtering date with newsletter