Skip Navigation

[Resolved] make more than 50 posts show on paginated view

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

Problem: I would like to be able to show more than 50 results per page using pagination, but I don't have the option to set a higher value using the GUI.

Solution: Use the wpv_view_settings filter to manually set the number of posts per page. Note that the number will not appear accurately in the form settings GUI, but will function as expected.

//Modify the limit and/or offset settings of a given View to use a number greater than 50:
add_filter( 'wpv_view_settings', 'prefix_modify_filter_offset_view', 5, 2 ); 
function prefix_modify_filter_offset_view( $view_settings, $view_id ) {
    if ( $view_id == 374 ) { // modify 374 to match your View ID
        $pagination = $view_settings['pagination']; // get the pagination settings
        $pagination['posts_per_page'] = 100; // modify this number accordingly
        $view_settings['pagination'] = $pagination; // save with updated pagination settings
    }
    return $view_settings;
}

Relevant Documentation: https://toolset.com/documentation/programmer-reference/views-filters/#wpv_view_settings

This support ticket is created 7 years, 7 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 6 replies, has 2 voices.

Last updated by peg 7 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#505998

peg

Hi there,
I have a paginated view where I want to show 100 results on every page instead of just max. 50.
I guess I need the filter:

//Modify the limit and/or offset settings of a given View to use a number greater than 50:
add_filter( 'wpv_view_settings', 'prefix_modify_filter_offset_view', 5, 2 ); 
function prefix_modify_filter_offset_view( $view_settings, $view_id ) {
    if ( $view_id == 374 ) { // if displaying a View with ID equal to 374
        $view_settings['limit'] = 75; // show 75 posts
        $view_settings['offset'] = 60; // skip the first 60 posts
    }
    return $view_settings;
}

What would be the correct $view_settings['..??..'] for this case? I couldn't find any documentation about the view settings.

Thanks,
Peg

#506012

Hi there, you've got the right idea. The 'limit' value sets the maximum number of posts shown on a page, and the 'offset' value tells the View to skip the first offset results.

So in your case, if you do not want to modify the default 'offset' supplied in the wp-admin area, you can remove that line (line 6 in your sample above). If you want to show 100 posts instead of 75, you can change the value in the 'limit' assignment:

$view_settings['limit'] = 100; // show 100 posts

Please let me know if I can help clarify this further.

#506013

peg

Hi Christian,
Thanks for your quick reply.
I have tried it with the "limit" option but this makes the view only show 100 posts and removes the pagination. I was thinking about "posts_per_page" or something but I don't know how to get the exact naming of the setting responsible for post limits per page. You have any insight about all the settings that a view would query?

#506437

Hi, thanks for clearing up the misunderstanding for me. Instead of the 'limit' attribute, you will need to make a modification to the pagination array's 'posts_per_page' value. Here's how that can be done:

//Modify the limit and/or offset settings of a given View to use a number greater than 50:
add_filter( 'wpv_view_settings', 'prefix_modify_filter_offset_view', 5, 2 ); 
function prefix_modify_filter_offset_view( $view_settings, $view_id ) {
    if ( $view_id == 374 ) { // if displaying a View with ID equal to 374
        $pagination = $view_settings['pagination']; // get the pagination settings
        $pagination['posts_per_page'] = 100; // modify posts per page
        $view_settings['pagination'] = $pagination; // save with updated pagination settings
    }
    return $view_settings;
}
#507970

peg
Image 2.jpg

Hi Christian,
Sorry for the delay and thank you for your support.
It seems to work.
I have just one question left: With the filter active, and as soon as I have posts_per_page set to a number larger than 50 the view's pagination options show: "Display 1 items per page" (see attached screenshot).
Is that correct? It would be helpful if it would show the actual number from the filter.
Thanks,
Peg

#507989

Hi, since we're overriding this option in the backend, I don't have a good solution for displaying the correct number here. I agree it's a bit confusing, but until we offer a feature to set your own arbitrary number here, it's not going to appear accurately.

#507990

peg

Ok.
Plus 1 from me for this feature.
Thanks again.
Closing the ticket.