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');
  • 1
    It's tangential to your question, but instead of using remove_action in this case (which avoids affecting subsequent queries in the sidebar and stuff) you can just use is_main_query($query) at the start of the function. That will ensure it only fires on the "main" (first, core) query of the page and not others.
    – jerclarke
    Sep 21 '12 at 19:02
  • Appreciate and will try and get back to you.. Thanks again Sep 21 '12 at 19:38

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');
  • Wonderful! perfect.. superb.. haha thanks a lot... working just like wanted.... :) Aug 21 '12 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.