D
D
Dmitry2017-08-11 15:16:13
JavaScript
Dmitry, 2017-08-11 15:16:13

Pagination with multiple wp_query + offset's?

In this way, I make 7-8 posts custom, everything works fine in category.php, but pagination is nowhere, apparently due to offsets or something else... Has anyone encountered this? how to make pagination work correctly?

<?php 
$categories = get_queried_object_id();
  $args = array(
  'posts_per_page' => 6,
  'cat' => $categories
);
$ar = array(
  'posts_per_page' => 2,
  'offset' => 6,
  'cat' => $categories
);
$arg = array(
  'posts_per_page' => 6,
  'offset' => 8,
  'cat' => $categories
);

$query = new WP_Query( $args );
$q = new WP_Query($ar);
$qu = new WP_Query($arg);

if ( $query->have_posts() ) {
  while ( $query->have_posts() ) {
    $query->the_post(); ?>
// содержимое обычное
 <?
  }
} 
wp_reset_postdata();

if ( $q->have_posts() ) {
  while ( $q->have_posts() ) {
    $q->the_post(); ?>
// содержимое "необычное"
 <?
  }
} 
wp_reset_postdata();

if ( $qu->have_posts() ) {
  while ( $qu->have_posts() ) {
    $qu->the_post(); ?>
//содержимое обычное
 <?
  }
} 
wp_reset_postdata();

Answer the question

In order to leave comments, you need to log in

4 answer(s)
0
0xD34F, 2019-03-31
@prukon

Leave the regex as it is, and just strip off the first few characters you need :
In general, perhaps you should look towards ready-made solutions ( for example ), instead of doing such bicycle building.

A
Alex, 2019-03-31
@Kozack

https://tproger.ru/articles/regexp-for-beginners/

A
Alexander, 2019-03-31
@zkelo

Try this regular expression - /^[\+\d]{1,12}$/g
Regex101

I
Igor Vorotnev, 2017-08-14
@HeadOnFire

Pagination works from the main query (Main WP_Query), and not from custom ones, and offsets have nothing to do with it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question