function customize_homepage_query( $query ) { if ( $query->is_main_query() && is_home() ) { $query->set( 'posts_per_page', 12 ); } } add_action( 'pre_get_posts', 'customize_homepage_query' );
function add_custom_query( $query ) { if ( ! is_admin() && $query->is_main_query() && is_page( 'about' ) ) { $query->set( 'cat', '1' ); } } add_action( 'pre_get_posts', 'add_custom_query' );In this example, the function will add a custom query to the main query on the "About" page. It will only show posts under category ID 1. The WP_Query is_main_query function is part of the WordPress core and does not require any external package libraries.