Skip Navigation

[Resolved] Split: View All link in Taxonomy Archives – Product Categories – change posts per page

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

Problem:
Taxonomy Archives – Product Categories - change posts per page

Solution:
You should use the WordPress hook "pre_get_posts" to override the number of posts to display.

You can find the proposed solution in this case with the following reply:
https://toolset.com/forums/topic/split-view-all-link-in-taxonomy-archives-product-categories-change-posts-per-page/#post-1246461

Relevant Documentation:
https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

This support ticket is created 5 years, 10 months 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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by annC 5 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#1246452

How could we do this dynamically, so the archive loads with pagination first and then will only turn pagination off or set a higher limit when the view all link is clicked?

#1246461

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - I've added the following code to Toolset's "Custom Code" section to override the number of posts to display when you click on view all link:

add_filter('pre_get_posts','func_include_child_terms',999);
function func_include_child_terms( $query ) {
     if (!is_admin() && $query->is_main_query() and  $query->is_tax( 'product_cat' ) and $query->queried_object->parent == 0 ) {
      $query->set( 'posts_per_page', 999 );
      
  }

    return $query;
}

Now, if you click on "View all" on the child category it will display 999 posts so you will not have pagination.:
=> hidden link

More info:
=> hidden link

#1246491

Thanks for the solution Minesh

I just had to make a couple of small modifications

I changed the archive for product categories view link so it would reload the current category.

[wpv-view name="view-tax-archive-link" terms="[wpv-taxonomy-archive info='parent']"] 

to

 [wpv-view name="view-tax-archive-link" terms="[wpv-taxonomy-archive info='id']"]

I also removed the parent check in the "Custom Code"

and $query->queried_object->parent == 0