You should adapt it to fit your needs, e.g. (not tested) :
// Create a new filtering function that will add our where clause to the query
function filter_where( $where="" ) {
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-1 year')) . "'";
return $where;
}<br>
add_filter( 'posts_where', 'filter_where' );
$query = new WP_Query( $query_string );<br>
remove_filter( 'posts_where', 'filter_where' );
Related Posts:
- How to display by default only published posts/pages in the admin area?
- Is there an if statement that can determine if a post in the loop is the last post?
- WP_Query: Why is sticky post not first item in loop?
- Is there a way to disable the sticky posts feature?
- How to remove Nextpage tag inside posts text depending of utm_campaign
- using slug instead of ID in admin edit post url
- Can I load posts via Ajax?
- Filter posts by author and category simultaneously
- All WordPress scheduled posts are being published immediately
- WordPress Delete hook with wp_delete_post function?
- Undelete post (untrash)?
- Double count view in archive.php
- disable column on post and user list
- Multiple social buttons with a fast loading? [closed]
- How can I display widget in a Page or Post?
- Different style for most recent article
- How can I replace the text at the top of a custom column into a icon?
- count the total number of comments the user has received for his published posts
- How to Orderby Comments by post title?
- If modified on same day, show only time
- How is a gallery associated with some post in database?
- Multiple posts with fixed order position
- Display Meta Values in Custom Filter – Admin Custom Posts
- Automatically add custom fields value to wordpress post
- How to use format post in a pertinent way
- Get user categories with most posts in it
- How to create media library for each user?
- How to display two blog categories as separate sections on one page?
- Retrieve post ID from “querying” URL
- When open add new post or page WordPress add post with ID=0 continuously [closed]
- Thumbnail & Category link aside post
- My wordpress based site is publishing the same post twice
- How to make a sum of all posts displayed in a loop
- First x post with another template then the others
- When creating a post how do you select the format?
- How can I post exact same post but with a few things changed? (with some sort of Automation)
- Assign published posts to another user automatically
- add bootstrap post slider with tabs
- Show all posts shows a blank white page in WP 4.2.2 [closed]
- Fast publishing in wordpress
- Getting Duplicate Posts on Home Page with Widget Added Between Posts
- Add Blog to WP homepage Manually
- Get URL from all images in a post
- Change the default blog post post attribute template name from “default template” to something else
- Getting property of non-object when looping through post objects from ACF
- How to get the ability to change the author of a post
- Defined function isn’t showed on page
- single post showing blank page in custom template
- How to enable custom Shortcodes in Post Category Description? [duplicate]
- Get total post from an author
- How to embed the content of one post into another site
- Prohibit saving a post without providing a title
- Limiting post list by taxonomy
- select post preview image from nextgen gallery
- How to add tag(s) to all posts from a specific category? [duplicate]
- Standalone form does not post to the url when form fields are populated (otherwise it does)
- Will multiple category descriptions effect my search engine optimization?
- Different post views for different category views
- “Home” Page now only displaying the single latest post
- How to prevent to create same url of post, if the previous was deleted?
- How to select a category automatically based on a word in WordPress post title?
- Open posts in popup window
- How to merge the content of posts that have the same title?
- How to allow WordPress to recognize a custom URL segment after a product URL and use a custom template?
- ‘QTags.addButton: arg2 distorts the button rather than just shows
- WordPress Post 403 Error Based on Slug
- How to add first 3-4 post tags on WordPress Post Title
- WordPress React re-rendering to many times
- Post feature image after post title for single post
- How do I assign an attachment to a post using only the REST API?
- How to add class to specific navbar item when post parent category is in specific category
- How to get unmodified post content?
- Posts are not displaying on their category and tag page
- Random post_id at wp_insert_post
- Sorting post by custom field and category
- WordPress display page information rather than post
- Post Category link is same with Page link
- I need show posts by customer (Shortcode)
- Show custom post category for single post
- How to delete all posts with dead image urls?
- Get a list of categories that are related to posts
- Allow reader to reorder posts for themselves (oldest first)
- Surrogate ID for posts, is there an alternative field in the posts table?
- List of authors posts minus very latest
- How do I get thumbnails?
- Add category attribute to custom recent post shortcode
- How can I show my post under a certain content name?
- How Can I Limit Users to Post Creation For My Frontend Theme?
- how to create add-able metaboxes in wordpress post edit screen?
- How to display only one post on first category page and rest on next pages?
- Show Custom Post From Logged In Author
- How to display a paginated list of posts from one category on a page? [duplicate]
- Is there a way to separate wordpress titles from their posts?
- custom sort posts in archive/taxanomy page
- Trying to create shortcode listing custom posts, but formating not being included
- Show Title/Date/Excerpt of first post & only Title for rest in Query [duplicate]
- remove description in colum title post
- Show some texts in posts belonging to Specific category
- How to automatically convert a form with HTML link into post
- WordPress Post Updating is Not Working