You are setting null
to $wp_query
then querying get_query_var( 'paged' )
this is expected that you will get this error!
First query get_query_var( 'paged' )
then set the original $wp_query
to null
Example:-
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
global $wp_query;
$temp = $wp_query;
$wp_query = new WP_Query( 'posts_per_page=2&paged='.$paged );
while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<h2>
<a href="https://wordpress.stackexchange.com/questions/225358/<?php the_permalink(); ?>"><?php the_title(); ?></a>
</h2>
<?php the_excerpt(); ?>
<?php endwhile; ?>
<div class="navigation">
<div class="alignleft"><?php previous_posts_link( '« Previous' ); ?></div>
<div class="alignright"><?php next_posts_link( 'More »' ); ?></div>
</div><?php
wp_reset_postdata();
$wp_query = $temp;
NOTE: Do not forgot to add
wp_reset_postdata()
after loop.