0

The query works for the default blog and pages but not for custom post archives. Did I miss something?

$paged_bottom = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
              $args_pagination_bottom  = array(
                  'format'    => '?paged=%#%',
                  'current'   => intval($paged_bottom),
                  'total'     => intval($GLOBALS['wp_query']->max_num_pages),
                  'mid_size'  => 2,
                  'prev_text' => '<i class="fa fa-arrow-left"></i>',
                  'next_text' => '<i class="fa fa-arrow-right"></i>',
              );

              echo paginate_links($args_pagination_bottom);

i tried this

public function __construct()
              {


                  add_action( 'pre_get_posts', array($this, 'ggowl_archive_posts_per_page'),20,1 );

              }

              public function ggowl_archive_posts_per_page( $query ) {
                  // var_dump($query);

                  if ( $query->is_archive('product') || $query->is_category() ) {
                      set_query_var('posts_per_page', 1);
                  }
              }

this works outside the class. How can i make it work in class?

2
  • What's the code for your actual loop? Commented Sep 14, 2019 at 2:25
  • @JacobPeattie it's having the same common used structure, just with query loop. I think it should not be used in class as multiple instances of the same code runs every time the class is called. So I created a sperate options page for controlling this setting and now it's working good. Thank you
    – user145078
    Commented Sep 14, 2019 at 16:13

1 Answer 1

-1

You might need a different var ... set_query_var('posts_per_archive_page', 1);

posts_per_archive_page (int) – number of posts to show per page – on archive pages only. Over-rides posts_per_page and showposts on pages where is_archive() or is_search() would be true.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.