I am trying to exclude pages from my search result with this function:
function posts_for_current_author($query) {
global $user_level;
if($query->is_admin && $user_level < 5) {
global $user_ID;
$query->set('author', $user_ID);
unset($user_ID);
}
unset($user_level);
if ($query->is_search && $query->is_main_query()) {
$query->set('posts_per_page', 9);
$query->set( 'post_type', 'post' );
}
return $query;
}
add_filter('pre_get_posts', 'posts_for_current_author');
In if($query->is_search)
i have a $query->set( 'post_type', 'post' );
but that one does not want to work, even though $query->set('posts_per_page', 9);
works... So my mind is blown here. Anyone know how to fix this?