setting custom posts per page affects admin panel

Hi. I am trying to set the query post per page to -1 for all queries but it is causing problems in the admin panel.

currently my code is


add_action( 'pre_get_posts', 'custom_query_vars' );
function custom_query_vars( $query ) {
  if (  ! is_admin() && $query->is_main_query() ) {
	$query->set( 'posts_per_page', -1 );
  }
}

but this is not correctly setting the posts per page in my query.

When I remove the && $query->is_main_query() then the query displays all posts, as intended, but while editing pages the admin panel does not show reusable blocks and the query loop preview does not load anything.

Any ideas about how I may be able to achieve setting the posts per page to -1 for all queries on the site without these undesirable effects?

The page I need help with: [log in to see the link]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Your Advertisement Here