Skip Navigation

[Resolved] change the number of posts per page

This thread is resolved. Here is a description of the problem and solution.

Problem:
The user would like to allow the site visitors to change the pagination of a page(5, 10, 25, 50 posts per page)

Solution:
This feature is not available by default in Toolset. It will need custom code. Check the user solution here https://toolset.com/forums/topic/change-the-number-of-posts-per-page/#post-1803239

This support ticket is created 4 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 2 replies, has 2 voices.

Last updated by Jamal 4 years, 1 month ago.

Assisted by: Jamal.

Author
Posts
#1802855

Hi, I've built a Product View that works just like the archive page (same filters, same pagination...). I would like to activate the "per-page" buttons just like on the archive page, but I found the custom code doesn't work here.

I tried to add a condition on func_include_child_terms:

add_filter('pre_get_posts','func_include_child_terms',999);
function func_include_child_terms( $query ) {
if ( ( $query->is_main_query() && $query->is_tax( 'product_cat' ) ) || ( $query->is_main_query() && is_page(14053) ) ) {

but it doesn't work. Can you help me again?

#1802893
#1803239

Hey Jamal, I could create the script by myself.

This is what I set up:

/* func_view_posts_per_page */
add_filter( 'wpv_filter_query', 'func_view_posts_per_page', 99, 3 );
function func_view_posts_per_page( $query_args, $view_settings, $view_id ) {
  $views = array( 14054 );
  if ( in_array( $view_id, $views ) ) {
    $pager = my_pager_func();
    if ( $pager > 0 ) {
      $query_args['posts_per_page'] = $pager;
    }
  }
  return $query_args;
}

It works fine. I've also found an issue on the JS code.
ajax_reload_with_pager function was triggering a specific Brand checkbox ('#pa_brand-airav), but it doesn't exist on all the archive pages and on the search page:

function ajax_reload_with_pager(){
  jQuery('.per-page a').off('click').on('click', function(event){
    event.preventDefault();
    var link = jQuery(this);
    var nposts = link.data('pager');
    var pager = jQuery('input[name="pager"]');
    pager.val(nposts);

     jQuery('#pa_brand-airav').trigger('change');

  })
}

My solution is to add an hidden submit button and click it to trigger ajax_reload_with_pager:


[wpv-filter-submit class="btn-submit" style="display:none"]

jQuery('.btn-submit').trigger('click');

My issue is resolved now. Thank you!

#1803443

Awesome! I wanted to start working on it when I realized that the ticket was resolved.

I am glad, you could fix it.