Why is not displayed pagination WordPress?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
12 views
There is a page template. It displays the posts from a custom post type. Trying to get pagination
<?php the_posts_pagination( array('show_all'     => true 'prev_next' => false, 'add_args' => false, 'add_fragment' => ", ) ); ?>

Displays anything. Apparently due to the fact that $GLOBALS['wp_query']->max_num_pages viswasam 0. Posts 4 if
'posts_per_page' => '2', 'posts_per_archive_page' => '2',

Found the pattern - If the code to insert directly on the page, the pagination starts to work. If using add and the do_action function. Need some kind of global variable? Tell me what it is.
by | 12 views

1 Answer

0 like 0 dislike
Hi!
Will lead a working piece of code, where I for myself solved this problem.
$term = get_queried_object(); $term_slug = $term->slug; $paged = ( get_query_var( 'page' ) ) ? get_query_var( 'page' ) : 1; $_posts = new WP_Query( array( 'post_type' => 'product', 'posts_per_page' => 10, 'paged' => $paged, 'tax_query' => array( array( 'taxonomy' => 'product-category', 'field' => 'slug', 'terms' => $term_slug, ), ), ) ); global $wp_query; $tmp_query = $wp_query; $wp_query = null; $wp_query = $_posts; if ( $_posts->have_posts() ) : while ( $_posts->have_posts() ) : $_posts->the_post(); get_template_part( 'template-parts/content-product', 'preview' ); endwhile; the_posts_pagination( array( 'type' => 'list', 'prev_text' => '', 'next_text' => '', ) ); else : get_template_part( 'template-parts/content', 'none' ); endif; $wp_query = null; $wp_query = $tmp_query; wp_reset_postdata();
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked May 21, 2019 by alexander_chn
0 like 0 dislike
1 answer
0 like 0 dislike
3 answers
asked Aug 2, 2019 by Lord_Dantes
0 like 0 dislike
1 answer
110,608 questions
257,187 answers
0 comments
40,796 users