[wp-hackers] Including custom post types on archive pages
Frank Bueltge
frank at bueltge.de
Thu Jun 9 11:54:30 UTC 2011
See this gist for a example: https://gist.github.com/998648
Best regards
Frank
On Thu, Jun 9, 2011 at 1:14 PM, Andrew Nacin <wp at andrewnacin.com> wrote:
> On Thu, Jun 9, 2011 at 3:10 AM, 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?
>
>
> On pre_get_posts, do a $query->set( 'post_type', array( 'post', 'page',
> 'book' ) );
> _______________________________________________
> 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