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

Otto otto at ottodestruct.com
Thu Jun 9 17:41:23 UTC 2011


On Thu, Jun 9, 2011 at 12:34 PM, Rafael Ehlers <rafaehlers at gmail.com> wrote:
> 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');

No, it'll work, but by accident rather than design. :)

This would work just as well:

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


-Otto


More information about the wp-hackers mailing list