Site icon Hip-Hop Website Design and Development

Pagination not working in customized loop WP_Query

Please assist with pagination

I’ve code that works advantageous (capabilities.php)

operate projects_custom_number_of_posts( $question ) {
    $query->set( 'posts_per_page', 2 );
    return;
}
add_action( 'pre_get_posts', 'projects_custom_number_of_posts');

once I change to, pagination stops working

operate projects_custom_number_of_posts( $question ) {
    $postsperpage = $query->get( 'posts_per_page' );
    $query->set( 'posts_per_page', $postsperpage );
    return;
}
add_action( 'pre_get_posts', 'projects_custom_number_of_posts');

It’s mandatory that the information is taken from the ‘posts_per_page’

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('product_cat' => $cat, 'post_type' => 'product',  'posts_per_page' => 2, 'paged' => $paged ); $question = new WP_Query( $args );

if ( $query->have_posts() ) : whereas ( $query->have_posts() ) : $query->the_post();