title: Wordpress static page template pagination not working
body: <p>I'm building a custom page template and I can't seem to get the pagination to work. It keeps showing the same posts as on the home/first page. I have tried a lot of different code but getting the same problem with each results.</p>
  
  <p>This is the current query I am using:</p>
  
  <pre><code>&lt;?php 
  global $paged;
  global $wp_query;
  $temp = $wp_query; 
  $wp_query = null; 
  $wp_query = new WP_Query(); 
  $wp_query-&gt;query('posts_per_page=2&amp;post_type=post'.'&amp;paged='.$paged);
  while ($wp_query-&gt;have_posts()) : $wp_query-&gt;the_post(); 
  ?&gt;
  
  &lt;div class="news-item"&gt;
    &lt;?php
    $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post-&gt;ID), '' );
    $url = $thumb['0'];
    ?&gt;
    &lt;div class="news-item-bg" style="background-image:url(&lt;?=$url?&gt;);"&gt;&lt;/div&gt;
  
    &lt;a href="&lt;?php the_permalink() ?&gt;" rel="bookmark" title="Permanent Link to &lt;?php the_title_attribute(); ?&gt;"&gt;
      &lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;/h2&gt;&lt;/a&gt;
      &lt;div class="entry-meta"&gt;
        &lt;div class="meta-date"&gt;&lt;?php the_time('d.m.Y'); ?&gt; &lt;/div&gt;&lt;div class="meta-seperator"&gt; | &lt;/div&gt;&lt;div class="meta-author"&gt;Auteur: &lt;?php the_author(); ?&gt;&lt;/div&gt;
      &lt;/div&gt;&lt;!-- .entry-meta --&gt;
      &lt;div class="excerpt"&gt;&lt;?php the_excerpt(); ?&gt;&lt;/div&gt;
    &lt;/div&gt;
  
  &lt;?php endwhile; ?&gt;
  
  &lt;?php previous_posts_link('&amp;laquo; Newer') ?&gt;
  &lt;?php next_posts_link('Older &amp;raquo;') ?&gt;
  
  &lt;?php 
  $wp_query = null; 
  $wp_query = $temp; 
  ?&gt;
  </code></pre>
  
  <p>Found the solution, this code worked:</p>
  
  <pre><code>&lt;?php
  if ( get_query_var('paged') ) {
      $paged = get_query_var('paged');
  } elseif ( get_query_var('page') ) { // 'page' is used instead of 'paged' on Static Front Page
  $paged = get_query_var('page');
  } else {
      $paged = 1;
  }
  
  $custom_query_args = array(
      'post_type' =&gt; 'post', 
      'posts_per_page' =&gt; '2',
      'paged' =&gt; $paged,
      'post_status' =&gt; 'publish',
      'ignore_sticky_posts' =&gt; true,
      //'category_name' =&gt; 'custom-cat',
      'order' =&gt; 'DESC', // 'ASC'
      'orderby' =&gt; 'date' // modified | title | name | ID | rand
      );
  $custom_query = new WP_Query( $custom_query_args );
  
  if ( $custom_query-&gt;have_posts() ) :
      while( $custom_query-&gt;have_posts() ) : $custom_query-&gt;the_post(); ?&gt;
  
  
  &lt;div class="news-item"&gt;
  
  
      &lt;?php
  
      if ( has_post_thumbnail() ) {
          $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post-&gt;ID), '' );
          $url = $thumb['0'];
  
          echo '&lt;div class="news-item-bg" style="background-image:url(&lt;?=$url?&gt;);"&gt;&lt;/div&gt;';         
      }
      else {
  
      }
      ;?&gt;
  
      &lt;a href="&lt;?php the_permalink() ?&gt;" rel="bookmark" title="Permanent Link to &lt;?php the_title_attribute(); ?&gt;"&gt;
          &lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;/h2&gt;&lt;/a&gt;
          &lt;div class="entry-meta"&gt;
              &lt;div class="meta-date"&gt;&lt;?php the_time('d.m.Y'); ?&gt; &lt;/div&gt;&lt;div class="meta-seperator"&gt; | &lt;/div&gt;&lt;div class="meta-author"&gt;Auteur: &lt;?php the_author(); ?&gt;&lt;/div&gt;
          &lt;/div&gt;&lt;!-- .entry-meta --&gt;
          &lt;div class="excerpt"&gt;&lt;?php the_excerpt(); ?&gt;&lt;/div&gt;
          &lt;div id="single-post-container"&gt;&lt;/div&gt;
          &lt;a class="button-1 load-more" href="&lt;?php echo get_permalink(); ?&gt;"&gt;Lees meer&lt;/a&gt;
          &lt;a class="ajax-close button-1" href="#"&gt;X&lt;/a&gt;
      &lt;/div&gt;
  
      &lt;?php
      endwhile;
      ?&gt;
  
      &lt;?php if ($custom_query-&gt;max_num_pages &gt; 1) : // custom pagination  ?&gt;
          &lt;?php
          $orig_query = $wp_query; // fix for pagination to work
          $wp_query = $custom_query;
          ?&gt;
          &lt;nav class="prev-next-posts"&gt;
              &lt;div class="prev-posts-link"&gt;
                  &lt;?php echo get_next_posts_link( 'Older Entries', $custom_query-&gt;max_num_pages ); ?&gt;
              &lt;/div&gt;
              &lt;div class="next-posts-link"&gt;
                  &lt;?php echo get_previous_posts_link( 'Newer Entries' ); ?&gt;
              &lt;/div&gt;
          &lt;/nav&gt;
          &lt;?php
          $wp_query = $orig_query; // fix for pagination to work
          ?&gt;
      &lt;?php endif; ?&gt;
  
      &lt;?php
      wp_reset_postdata(); // reset the query 
      else:
          echo '&lt;p&gt;'.__('Sorry, no posts matched your criteria.').'&lt;/p&gt;';
      endif;
      ?&gt;
  </code></pre>