I'd like to set up a query that shows only posts in a specific category that were published in the last 15 days, and excluding any sticky posts. I presumed it would look something like this, based on the WP Query documentation, but this doesn't work:
[archivist query="category=streaming&strtotime=-15 days&ignore_sticky_posts=1"]
What am I doing wrong here?
http://wordpress.org/extend/plugins/archivist-custom-archive-templates/
eteubert
Member
Plugin Author
Posted 1 year ago #
The WordPress API doesn't allow something like "the last x days/weeks/...". You can only query for a certain date/month/year as shown here: http://codex.wordpress.org/Class_Reference/WP_Query#Time_Parameters
[archivist query="category=streaming&year=2012&monthnum=2&ignore_sticky_posts=1"]
strtotime is not supported by the WP_Query API. I might be able to add that functionality to the plugin but it's not trivial. Don't hold your breath.
I thought you could add strtotime to a loop with this:
// Create a new filtering function that will add our where clause to the query
function filter_where( $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' );
$query = new WP_Query( $query_string );
remove_filter( 'posts_where', 'filter_where' );
...because it was in the codex. I'm not going to argue with you though. If I knew this stuff well enough to speak intelligently I wouldn't be asking for help! ;-)
Thanks for the updated shortcode!
eteubert
Member
Plugin Author
Posted 1 year ago #
Well, not quite :) That's just an example code snippet for plugin or theme developers to get an idea how to implement something like that. I'll try to implement it when I find some spare time.
Cool! It'd make this project really powerful, IMO.