1
global $wp_query;
$result = $wp_query;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$original_query = $wp_query;
$wp_query = null;
$args=array(
    'post_type'=> 'post',
    'orderby'    => 'ID',
    'post_status' => 'publish',
    'order'    => 'DESC',         
    'posts_per_page'=>get_option( 'posts_per_page' ),
    'paged'=>$paged
);
$wp_query = new WP_Query( $args );
$result = new WP_Query( $args );
if ( $result-> have_posts() ) : ?>
    <?php while ( $result->have_posts() ) : $result->the_post(); 
          get_template_part( 'template-parts/content', get_post_type() );
     endwhile; 
     echo "<div class='pagenum_link'>";
         $total_pages = $result->max_num_pages;
         if ($total_pages > 1){
             $current_page = max(1, get_query_var('paged'));
             echo paginate_links(array(
                 'base' => get_pagenum_link(1) . '%_%',
                 'format' => '/page/%#%',
                 'current' => $current_page,
                 'total' => $total_pages,
                 'prev_text'    => __('«'),
                 'next_text'    => __('»'),
             ));
         }
     echo "</div>";
else :
     get_template_part( 'template-parts/content', 'none' );
endif; 
wp_reset_postdata(); ?>
  • My answer was downvoted. Did you actually try it? If it didn't work, let me know and I can try and help further. – TomC Apr 8 at 6:51
  • yes i try this code its not working – bobby kumar Apr 14 at 10:04
-1

Remove the following line from your $args array:

'post_type'=> 'post',

Or change it to:

'post_type'=> 'any',

This is only running the query on posts and will not work on pages. The following explains this in more detail: https://wordpress.org/support/article/post-types/

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.