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

Steve Taylor steve at sltaylor.co.uk
Thu Jun 9 10:57:36 UTC 2011


Maybe a query_posts in archive.php?

http://codex.wordpress.org/Function_Reference/query_posts


On 9 June 2011 08:10, Philip Walton <philip at philipwalton.com> wrote:
> 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?
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list