Skip Navigation

[Resolved] View – newest 100

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

Problem: I would like to use a View to display 100 results in reverse chronological order based on the post date.

Solution:
In the View Editor, find the Ordering section and choose post_date, descending. Change the Limit to 50 (this number will be overridden by code).,

add_filter( 'wpv_view_settings', 'tssupp_modify_filter_offset_view', 5, 2 );
function tssupp_modify_filter_offset_view( $view_settings, $view_id ) {
  $views = array( 12345 );
  $max = 100;
    if ( in_array($view_id, $views) ) {
 
        $view_settings['limit'] = $max;
    }
    return $view_settings;
}

Change 12345 to match the View's ID.

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

This support ticket is created 5 years, 5 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 4 replies, has 2 voices.

Last updated by reimundH 5 years, 5 months ago.

Assisted by: Christian Cox.

Author
Posts
#1270523

Hello,

could you please tell me how I create a view which show only the newest 100 results.
Thanks in advance.

Best regards
Reimund

#1270753

Hi, to order by date in reverse chronological order, edit the View and make sure you can see the "Ordering" section. If you cannot see it, scroll to the top right corner and click "Screen Options". Enable Ordering. Then you will choose "post date" and "descending" as the ordering settings.

To display the top 100 results, it's more complicated. You cannot choose a number greater than "50" in the Limit section of the View editor, but you can override the number with some custom code. Here's an example:

add_filter( 'wpv_view_settings', 'tssupp_modify_filter_offset_view', 5, 2 ); 
function tssupp_modify_filter_offset_view( $view_settings, $view_id ) {
  $views = array( 12345 );
  $max = 100;
    if ( in_array($view_id, $views) ) {
        $pagination = $view_settings['pagination']; // get the pagination settings
        $pagination['posts_per_page'] = $max; // modify this number accordingly
        $view_settings['pagination'] = $pagination; // save with updated pagination settings
    }
    return $view_settings;
}

Change 12345 to match the numeric ID of this View. You can also change 100 if you would like to modify the maximum number of results. Add the code to a new code snippet in Toolset > Settings > Custom Code tab, or add it to your child theme's functions.php.

One thing I would like to mention is that the View editor screen will still show an incorrect limit, but the code will override the setting in the View editor screen.

#1270785

Hi,

so is it 100 per page?
Or maximum 100 results at all?

In this case I need maximum 100. Several pages are okay.

Best regards
Reimund

#1271007

Ah, okay I misunderstood. Here is an update that will set a maximum number of total results, while leaving your pagination settings unchanged. Just update the View ID like before.

add_filter( 'wpv_view_settings', 'tssupp_modify_filter_offset_view', 5, 2 );
function tssupp_modify_filter_offset_view( $view_settings, $view_id ) {
  $views = array( 12345 );
  $max = 100;
    if ( in_array($view_id, $views) ) {

        $view_settings['limit'] = $max;
    }
    return $view_settings;
}
#1271103

My issue is resolved now. Thank you!