Include Custom Posts Type in Year/Month/Date Archive

I am looking for solution where I able to get all custom post types in year, month and date archive list. So it can be filters by anything either year, month or date. I am looking for function something like below which I am using to include CPT for authors

function custom_post_author_archive($query) {
    if ($query->is_author)
        $query->set( 'post_type', array('wp_plugin_review', 'png_gallery', 'post', 'news') );
    remove_action( 'pre_get_posts', 'custom_post_author_archive' );
}
add_action('pre_get_posts', 'custom_post_author_archive');

Related posts

Leave a Reply

1 comment

  1. Your code simply adds post types to the query when on the author archive so to do the same with date archive simply replace is_author to is_date :

    function custom_post_date_archive($query) {
        if ($query->is_date)
            $query->set( 'post_type', array('wp_plugin_review', 'png_gallery', 'post', 'news') );
        remove_action( 'pre_get_posts', 'custom_post_author_archive' );
    }
    add_action('pre_get_posts', 'custom_post_date_archive');