I am hoping you can help. I need to make the following happen in a View I made.
If logged in user role is set to 'free', than change the display limit of items to 4
If logged in user role is set to 'paid', than change the display limit of items to all
Is this possible? It seems I can only set the display limit for the view in general and not use conditions to set it.
Thanks!
It's not possible natively in one View without using custom code.
The simplest is creating 2 Views, each paginated according to user roles' permissions, then insert both Views on the same page but wrap each in a Toolset Access (or HTML Conditional) ShortCode:
https://toolset.com/documentation/user-guides/access-control-texts-inside-page-content/
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
This allows you to show View A to user role A and View B to user role B.
If you want to do it in the same view, you'll need to filter the View's settings according to the current user.
You'd do this by adding your custom code which alters the Queries' max results settings, to the Views Filter here:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_view_settings
There is an example there which already almost does what you need:
//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 ); // use a low priority number of 5, so this runs early
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;
}
Now instead of only checking the View ID, you'd also check the current user role, this can be done with the WordPress API https://codex.wordpress.org/Function_Reference/current_user_can
Please let me know if you'd need more details on some step.
My issue is resolved now. Thank you!