Hi,
we would like to split the blog into a page called “News” with alle blog posts youger than a year and a page called “Archive” containing all blog posts older than a year.
We use pre_get_posts filter, which will work fine on other templates, but not on enfold.
This is the code we use :
/**
* Create date filter for posts older then current date
*/
function textdomain_date_range( $where = '' ) {
$where .= " AND post_date < DATE_SUB(NOW(),INTERVAL 1 YEAR)";
return $where;
}
/**
* Displays the Post older then current date
* @uses posts_where filer for data range
* @uses pre_get_posts hook
*/
function textdomain_older_posts( $query ) {
if ( is_page('Archiv') && $query->is_main_query() ) {
$query->set( 'order', 'ASC' );
add_filter( 'posts_where', 'textdomain_date_range' );
}
return $query;
}
add_action( 'pre_get_posts', 'textdomain_older_posts' );
The problem is, that no content ist displayed but we get a 404 Page. It is very strange, that when we alter the SQL query to somethin like that:
$where .= ” AND post_date < DATE_SUB(NOW(),INTERVAL 5 DAY)”;
it works perfectly. If I use a value higher than 5 DAY (eg. 7 DAY), i also get a 404. The SQL Query runs perfectly on the mysql server, and all values below 6 DAY work fine in wordpress.
Any help is appreciated to get this working.
Regards
Achim
Hi two_worlds!
I’m not sure what it could be. It’s kind of bordering on custom work though. Your absolutely sure this is working in the default theme?
I would try playing around with the date parameters in the query instead of using a SQL command, http://codex.wordpress.org/Class_Reference/WP_Query#Date_Parameters.
Cheers!
Elliott