custom post types - Pagination not working for archive

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

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?

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?

Share Improve this question edited Sep 13, 2019 at 19:58 asked Sep 13, 2019 at 19:06 user145078user145078 2
  • What's the code for your actual loop? – Jacob Peattie 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
Add a comment  | 

1 Answer 1

Reset to default -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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745158874a4614288.html

相关推荐

  • custom post types - Pagination not working for archive

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

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信