1

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');
2
  • 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
    Commented Sep 21, 2012 at 19:02
  • Appreciate and will try and get back to you.. Thanks again Commented Sep 21, 2012 at 19:38

1 Answer 1

3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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