We have an issue with our date archive in WordPress, where our daily archive (example address www.xxx.com/2013/01/09) is only generated when a post from the default post type is added. Any day where a default post type was not posted, results in a 404 not found.
If we go to a day where a default post type was posted, we have no problems seeing articles from all post types via this function (from another stackexchange thread)
function custom_post_date_archive($query) {
if ($query->is_date)
$query->set( 'post_type', array( 'news', 'sports', 'life', 'opinion', 'culture','community' ) );
remove_action( 'pre_get_posts', 'custom_post_date_archive' );
}
add_action('pre_get_posts', 'custom_post_date_archive');
We've also tried other functions where we generate a daily archive URL for each post type (for example www.xxx.com/news/2013/09/01), but that is not the URL format we would like.
Basically we would like a way to tell WP to generate the base daily archive URL when ANY post type is added.
This was working previously, however, when a separate rewrite function was added to the functions file, daily archive generation for all post types ceased. We've tried all types of rewrie flushing, to no avail (though the addresses do work, just that WP only thinks to generate www.xxx.com/2013/01/09 if a default post is made).
Is there a function that can tell WP to always generate that address whenever any post type is added? Or is there another way to flush the system?
$wp_query
in the 404 template to see the actual query sent to the database for a clue as to why you're getting a 404.remove_action
line, and changing theif
condition toif ($query->is_date() && $query->is_main_query())
.