I found this: http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query
I have modified the date to retrieve the last 15 days. It’s untested, but should work.
$expireDays="15";
$querystr = "
SELECT $wpdb->posts.*
FROM $wpdb->posts, $wpdb->postmeta
WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
AND $wpdb->posts.post_status="publish"
AND $wpdb->posts.post_type="post"
AND $wpdb->posts.post_date >= ( CURDATE() - INTERVAL $expireDays DAY )
ORDER BY $wpdb->posts.post_date DESC
";
$pageposts = $wpdb->get_results($querystr, OBJECT);
Related Posts:
- Meta Query with AND & OR?
- Upcoming Event: How do I sort database by custom date field, but ignore past dates?
- Query post by date (stored custom field meta as yyyymmdd) and differentiate across 12 months
- The best way to collision check in WP
- How to query for posts with either one or another custom field
- Complex WP_Query Using Post Date And Post Meta
- WP_Query – Order results by meta value
- Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
- Filter WP_Query for posts having a certain meta-value
- Can I query custom meta data through WP_Query
- How to rename a custom field?
- How can I make wp-pagenavi work on a custom query built upon a form submission? [closed]
- How do I search an array stored in a custom-field using WP_Query?
- How do I order by multiple custom fields using wp_query?
- Trying to perform complex custom field query with order by set to field value
- Query meta field using between
- Order Posts by Closest Numeric Values
- 2 orderby in wp_query with 2 custom fields
- Can serialized arrays in DB be matched against serialized arrays with meta_query?
- How to get a meta value from all post
- Compare meta_query decimals not working right
- WP_Query multiple use of relation and/or
- Query Problem – Show posts within category ‘x’ that have a custom field between ‘y’ and ‘z’
- Comparing timestamps in meta query doesn’t work
- Display two post types ordered by two custom fields
- Using OR in WP_Query negates the “NOT EXISTS” compare
- WP_query : meta_key with custom rule for specific value
- How can I combine meta_query queries?
- How to filter a dd/mm/yyyy date from a custom field in a query
- Having trouble with custom date field for CPT query (WordPress)
- Using WP Query to search by multiple meta fields
- Difference between ‘LIKE’ and ‘IN’ in meta queries
- Plugin similar to Taxonomy Drill-Down for custom fields?
- Compare WP Custom Field date
- Sort by posts that have a featured image?
- WP_Query display next custom post from today’s date
- Order by value in serialized custom field
- $wp_query meta_key naming issue [closed]
- Author Page Custom Query WHERE author OR [post meta value] OR [post meta value]
- How do I query for a post by custom field?
- Meta_query and numeric comparison [closed]
- Conditional to modify query results
- Count how many posts have a custom field set
- Adding Custom Fields to Search
- Any way to include custom fields in WP_Query results?
- sort search results by custom fields using dropdown
- Multiple relationships in a query
- How can I sort homepage by a meta value?
- Loop to display random posts only if a custom field matches category
- WP Query Returning All Posts
- How do I use wp_query for WordPress search?
- Meta query with timestamp using WP_query
- Order query by meta_value with multiple custom fields
- Conditionally hide or show woocommerce product variation in fontend by custom field
- Display only past events on that page using Visual Composer Grid Bulider
- Add quicklink to in the Admin posts page where I can query by a meta_key
- Custom Field Create Bulk via SQL Query
- Create Pop-Up Box with Custom Field Content Inside the Loop
- Auto Populate Custom Field with Complex Value That Increase by One?
- query usermeta from custom field
- Is there any way to get all meta and standard columns for any WordPress object after searching based on meta key and value
- Order RSS content by an advanced custom field value
- Order by empty custom field
- Alter main archive, to show posts with meta as last
- First custom field value (out of several) displayed twice after query
- Custom WP_Query for WordPress Search Results with meta_query
- Meta Query And/Or
- How to combine custom fields to make one order-able value
- Trying to reorder posts by custom field
- Limits, not all post are showen when querying for posts by view count
- Why orderbyb meta_value_num won’t affect the generated SQL Query order?
- Specific coditional usage [closed]
- Get post ids sorted by meta_key
- querying a custom field
- Passing meta_box string to post__in?
- pre_get_posts : only get posts by wp_usermeta value
- meta_value and meta_key filtering returning no posts [closed]
- Select custom posts by meta_value and sort by a different meta value
- Can’t query by meta_key
- Adding custom field and querying from post table
- How to query an out put value?
- List custom queried terms in the edit-tags.php?taxonomy page
- Modify date query by URL parameter using pre_get_posts and $_GET
- award points to a user each time they update their cpt post
- Loop through incrementing custom fields
- Custom search SQL Query to add custom field in result
- Meta query relation ‘OR’ not working as expected
- The conditional logic only works to show or hide?
- WP_query multiple custom fields not working
- How to exclude custom fields from search queries?
- Help with this custom field conditional if no field is set display nothing
- WP_Query () using taxonomy, custom post types
- Custom Query Fields – Altering Meta Value
- Multiple Custom Field Query
- Best way to sort estates and query them (for rent? yes/no. contains office space? yes/no)?
- Custom Query: query by post custom meta data
- Get array of posts based on custom field values
- How to update custom field of a posts in a particular category
- Searching with Multiple (Parallel) Criteria on Custom Fields?
- How to query posts by month based on date custom field?