Yes, simple add a filter before you call it and remove it after you do
function filter_where_wpa89154($where="") {
//posts in the last 30 days
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";
return $where;
}
add_filter('posts_where', 'filter_where_wpa89154');
$args = array(
'posts_per_page' => 5,
'post_type' => 'post',
'post_status' => 'publish',
'suppress_filters' => false
);
$posts = get_posts($args);
remove_filter('posts_where', 'filter_where_wpa89154');
notice the 'suppress_filters' => false
which is what makes this happen with get_posts
Related Posts:
- How to show related posts by category
- How to display posts by current user/author in a custom page template?
- How to get previous 10 days post from a specific date – WP Query
- Query only Posts from Both of Two Category?
- Can I set and show “important” post in my blog?
- Inserting custom data to the_post() during loop
- Why is querying posts messing up my pages?
- How to get posts from a current post’s month?
- While loop articles – if statement order
- Display Posts with template on a Page
- Post Filtering by GET URL parameters
- How to give classname to post if post has no content?
- Get posts from current category?
- How to merge the content of posts that have the same title?
- get posts, run a custom query, and join the results
- WP_Query to get posts in a specific tag or has post_format
- How to get all post titles starting with numbers and symbols?
- Word count for all posts of all authors
- Get Posts Under Custom Taxonomy
- Get the ID of the latest post
- the_author() returns empty string
- get_children() Not Working with orderby Parameter
- How to get all posts related to particular category name?
- How to know if get_posts() failed?
- post_name empty after wp_insert_post
- Setting pagination for images attached to a post
- Insert custom div between posts
- Only display posts with comments
- Different amount of posts on homepage than paged pages
- How Can i Get 5 Recent Post Title With Corresponding Link?
- Filter Posts By Tag
- Get specific posts by ID in wordpress
- Automatically republish old posts
- previewing my posts on static page?
- Exclude newest post from category X but show rest
- Reset Popular post query?
- How do I restart my loop with get_next_post()?
- Display posts with tag that matches current post title
- Category Foreach keeps looping?
- How to exclude latest x posts from a paginated query?
- Insert Content In Between Post Feed
- Get Posts Under Custom Taxonomy
- Pagination with an array of post objects?
- How to make multiple sections in home pulling posts category wise?
- wp_posts table: safely remove unused columns to save database storage
- Query Posts by Custom Field
- Posts loop displaying the same post data
- Display Posts on Custom Page
- How to get posts and comments amount per hour, per year and per month?
- Conditionals if tags exist?
- How to Get Posts, Including Private Ones?
- Random posts from a pool of posts
- Conditional Tag for has post [closed]
- Posts – display all posts except a post by an ID
- Counter is skipping post when I still want it visible [closed]
- why the same code got different results when using query_posts in functions.php and index.php
- Archive template combined with post slider and regular posts
- How to only publish posts with image in it
- wp_query with ajax
- WP_Query: Show 10 posts in date order, first three random
- Custom Articles page only showing a limited number of posts per page
- Random posts that always include a particular post?
- Bootsrap carousel for post
- How to get post with slug and exclude categories
- Get x recent posts by author?
- Get postlist for each category using query_posts?
- How to save posts position on homepage after random function?
- WordPress displays post on subcategory only
- Internal linking to posts permalink fail because of spaces and stripe at postname
- Trying to query all posts in category 4
- Change content off every sixth element
- How to add content above footer in posts from specific category
- Show posts from two specific category in WP_Query
- How to create loop of posts except post ID defined via ACF field
- Displaying all posts from other sites on the network on one site
- Multisite how to display merged posts from two sites and sort by latest date?
- How to display particular categorie’s post which associated to specific user?
- REST API Working for GET but not for POST?
- Fill the exclude array() in get_posts()
- How to add navigation arrows to manually slide through posts?
- Manipulate query to show specific post
- How to correctly escape data
- Blog posts not displaying on blog posts page
- How to convert return type of ‘get_posts()’ same as ‘wp_get_recent_posts()’?
- Sort Events by Venue Title – Sort Post set by related post ids
- Get posts by category or author
- get “read more” with custom DB query like you would with WP Query
- How to pass multiple checkbox values to wordpress query?
- How do I paginate posts page with $wpdb?
- How to inject a post within a loop
- Bulk Attach Or Insert Media To Post Without Opening Post Editor
- How to get alphabetic listing x other posts, based on first letter post?
- Displaying posts on Homepage
- How to get single post by one author?
- wp trim function not working
- wordpress show category link instead of post link [closed]
- posts_per_page – Repeats only first posts ‘post__in’ array
- query_posts different amount of posts per page [duplicate]
- append $_GET parameters to post
- Sort Posts Alphabetically Based on Specific Category (Divi)