• Resolved Roger

    (@erpol53)


    Hi,

    Your plugin is great and I use it on all my sites (with some creative CSS ;-), but I’ve hit a snag: I have a custom post type that I’d like to have appear in the archives, and I can’t find an easy way to do this.

    Any suggestions?
    Thanks,
    RP

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Ashley

    (@nosegraze)

    Sorry, but this plugin is only written with the “post” post type in mind. It could possibly be modified with custom code though.

    In the expanding_archives_get_months() function you’d have to use the provided filter to change the query to look for a custom post type instead of post.

    In NG_Expanding_Archives::get_current_month_posts() you’d have to use the expanding_archives_get_posts filter to filter the post query arguments to change the post type. And same in NG_Expanding_Archives::load_monthly_archives().

    I think that should do it.

    Thread Starter Roger

    (@erpol53)

    Hi, thanks for the supert quick response!

    I did try what you suggest, but it doesn’t seem to work.
    Before writing any filters I tried a simple fix in the function load_monthly_archives, by adding 'post_type' => array('my-post', 'post'), to

    $arc_args = array(
    	'posts_per_page' => - 1,
    	'nopaging'       => true,
    	'year'           => intval( $year ),
    	'monthnum'       => intval( $month ),
    	'post_type' 	 =>  array('my-post', 'post'),
    
    		);

    And it doesn’t change anything. I even tried 'post_type' => 'any', but no luck there either… What am I missing ?
    Thanks again for your help,
    RP

    • This reply was modified 5 years, 2 months ago by Roger.
    • This reply was modified 5 years, 2 months ago by Roger.
    Plugin Author Ashley

    (@nosegraze)

    That seems to work just fine for me. When I set it to any I start seeing pages appearing in my list.

    Are your post type entries definitely published during the specified month/year?

    Thread Starter Roger

    (@erpol53)

    Seriously, thanks for taking the time for this.

    Ok, I got it: I need to really clear the cache (best is deactivate / reactivate the plugin).
    But even then, the custom posts appear only for the months where there are already regular posts as well.

    For some reason, when displaying the months those with only custom posts get skipped. I can’t find why, since the function load_monthly_archives should return something even if there are only custom posts when it’s called in the loop.

    I even tested this by leaving only 'post_type' => 'my-post', : the same months are still shown, but with the mention “no posts found” if there are no custom posts!
    Could you point me to which function identifies if there are posts in a given month?

    Thanks for your help.

    Thread Starter Roger

    (@erpol53)

    Ok, found it! I put it here for future reference:

    In functions.php, replaced and post_type = 'post' by and (post_type = 'post' or post_type = 'my-post')

    Thanks again for helping me out!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom post types in archive’ is closed to new replies.