WordPress, excluding pages with pre_get_posts

i want to exclude all wordpress pages from all wordpress queries.

My idea to solve this problem was to set the posttype in pre_get_posts

Read More
function meta_filter_posts( $query )
{
  $query->set( 'post_type' => 'post' ); 
}

add_filter( 'pre_get_posts', 'meta_filter_posts' );

But it doesn’t work. I get no results. Why?

Related posts

Leave a Reply

2 comments

  1. Try it:

    function exclude_pages($query) {
        if ( !is_admin() && $query->is_main_query() ) {
           $query->set('post_type', 'post');
        }
    }
    
    add_action('pre_get_posts','exclude_pages');