WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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');
share|improve this question
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. – jeremyclarke Sep 21 '12 at 19:02
Appreciate and will try and get back to you.. Thanks again – pixelngrain Sep 21 '12 at 19:38
up vote 2 down vote accepted

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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