[wp-hackers] Including custom post types on archive pages

Philip Walton philip at philipwalton.com
Thu Jun 9 07:10:06 UTC 2011


I'm writing a plugin that lists your site's archives in an easy-to-read 
format, grouped by month and year. I'm also adding an option to specify 
which of your site's archives existing post types to include in the 
archive list.

The problem is when I generate the link to the archives page (e.g. 
example.com/2011), unless the theme is already set up to query those 
custom post types, the user will only see posts of type 'post'.

My idea was to add query vars when my plugin generates the URL (e.g. 
example.com/2011/?post_type=post,page,book) and then use a filter or 
hook to add the specified post type(s) to the query.

My initial inclination was to use the 'posts_where' filter and then 
modify the actual SQL statement, but that seems like it could be pretty 
messy and possibly unreliable.

Can anyone recommend a good way to do this?


More information about the wp-hackers mailing list