Bug in silvia_exclude_page_on_search()
-
In the function
silvia_exclude_page_on_search()
, there is a bug that overwrites any other post types added to the search query (“attachment”, for example, if someone wanted attachments to show up in search results).To fix the bug, the function should look something like this (untested):
function silvia_exclude_page_on_search( $query ) { if ( ! is_admin() ) { if ( $query->is_main_query() && $query->is_search ) { $post_types = $query->get( 'post_type' ); if ( is_array( $post_types ) && in_array( 'page', $post_types ) ) { unset( $post_types[ array_search( 'page', $post_types ) ] ); } $query->set( 'post_type', $post_types ); } } }
- The topic ‘Bug in silvia_exclude_page_on_search()’ is closed to new replies.