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

Rafael Ehlers rafaehlers at gmail.com
Thu Jun 9 17:34:49 UTC 2011


So, Nacin, you're saying this wont work, because of the add_filter instead
of add_action?

function filter_search($query) {
    if ($query->is_search) {
$query->set('post_type', array('post', 'pages','books'));
    }
    return $query;
}
add_filter('pre_get_posts', 'filter_search');

On Thu, Jun 9, 2011 at 2:23 PM, Andrew Nacin <wp at andrewnacin.com> wrote:

> On Thu, Jun 9, 2011 at 7:54 AM, Frank Bueltge <frank at bueltge.de> wrote:
>
> > See this gist for a example: https://gist.github.com/998648
> > Best regards
> > Frank
>
>
> Not really.
>
> pre_get_posts isn't a filter, it's an action where the query is passed by
> reference. So there's no return value, and it's add_action rather than
> add_filter.
>
> Don't check for suppress_filters. You're doing that to make sure this isn't
> a get_posts() call, rather than properly checking if this is the main
> query.
> The is_admin() and is_preview() checks are superfluous, given the is_home()
> and is_front_page() checks.
>
> So, a few options: Use the parse_request or request filters, which only
> fire
> on the main query. Or use $wp_the_query to confirm you're acting on the
> same
> query.
>
> Nacin
> _______________________________________________
> 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