A
A
Alexander Nameless082018-05-15 22:01:49
WordPress
Alexander Nameless08, 2018-05-15 22:01:49

What is the difference in the output methods?

Hello!
What is the difference in output?
Like this:

<?php
  global $wp_query;

  $wp_query = new WP_Query(array(
    'category_name' => 'blog', // 
    'posts_per_page' => '5',
    'paged' => get_query_var('paged') ?: 1 // страница пагинации
  ));

while(have_posts()) { the_post(); ?>
      <div><?php the_title(); ?></div>
<?php }

the_posts_pagination(); 

wp_reset_query(); // сброс $wp_query
?>

And this:
<?php 
    $query_projects = new WP_Query(array( 
      'category_name' => 'blog', 
           'posts_per_page' => 5
      ));
    ?>

       <?php while( $query_projects->have_posts() ): $query_projects->the_post(); ?>
                            <div><?php the_title(); ?></div>
             <?php endwhile; the_posts_pagination(); wp_reset_postdata(); ?>

Both use WP_Query and fetch blog posts. But in the first case, the output is through: while(have_posts()) { the_post();, and in the second
while( $query_projects->have_posts() ): $query_projects->the_post();
, while the first option allows you to display pagination through the_posts_pagination(); , but the second one is not.
What is the difference between these two options?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question