[wp-trac] [WordPress Trac] #21596: enhance wp_get_archives to support post types

WordPress Trac noreply at wordpress.org
Tue Jun 10 16:54:57 UTC 2014


#21596: enhance wp_get_archives to support post types
-------------------------------+------------------------------
 Reporter:  jjminkle           |       Owner:
     Type:  enhancement        |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Posts, Post Types  |     Version:
 Severity:  normal             |  Resolution:
 Keywords:  has-patch          |     Focuses:
-------------------------------+------------------------------

Comment (by jacklenox):

 Argh, so I've looked into this and it seems to be a fairly complex issue.

 The first part of the problem is quite straightforward. As above, we can
 allow the `wp_get_archives()` function to accept `post_type` as an
 argument.

 However, dealing with the URLs without getting a bit hacky seems
 difficult. It is of course fairly straightforward to use the
 `rewrite_rules_array` filter to handle some custom URLs but I get the
 impression this isn't best practice for core.

 Bearing that in mind, it looks as though we would need to rewrite the
 `get_date_permastruct` method of the `WP_Rewrite` class so that it can
 also handle a custom post type. Or we need to combine that method with a
 new one. I don't really know enough about the class to have a valid
 opinion.

 In the meantime I've created a plugin that contains a new function
 `wp_get_archives_cpt()` which is basically a clone of `wp_get_archives()`
 but the added `post_type` support. The plugin also comprises what I
 believe is the quickest, dirtiest way of dealing with the URL rewriting.
 Find it here: https://github.com/jacklenox/archives-for-custom-post-types

--
Ticket URL: <https://core.trac.wordpress.org/ticket/21596#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list