I had the same (or similar?) problem.
After restricting content for users through User Access Manager, the pagination isn’t functioning correctly. While my frontpage is set to 10 posts per page, some users get to see less or even no posts.
Davoron pinpointed the problem precisely: 10 posts are retrieved from the database, but before they are shown, the restricted posts are filtered out, leaving less or no posts to show.
The main query should already leave out the restricted posts. I added a filter to achieve this.
But that’s not all. There is also a problem with the method ‘getPostsForUser‘. It is only retrieving posts of the type ‘post’. That needs to be fixed too, in order to have pagination work with custom post types.
Sidenote: Big thanks to Davonon, for pointing me in the right direction: ‘getExcludedPosts‘ isn’t returning any posts (at least not in the case of this issue), but that is because it relies on the faulty getPostsForUser.
I fixed this problem by changing the plugins code in several places.
Add this to class/UamAccessHandler.class.php:
/**
* MY FIX TO MAKE PAGINATION WORK WITH CUSTOM POST TYPES
*
* @param arrray $query The query object
*
* @return void, $query is passed by refecence
*/
function AB_pre_get_posts( $query ) {
if ( is_admin() || ! $query->is_main_query() )
return;
$uamAccessHandler = &$this->getAccessHandler();
$usersPosts = $uamAccessHandler->getPostsForUser();
$query->query_vars['post__in'] = array_merge(
$query->query_vars['post__in'],
$usersPosts
);
return;
}
Trigger this method by adding a hook in user-access-manager.php, around line 340:
//MY FIX TO MAKE PAGINATION WORK WITH CUSTOM POST TYPES
add_filter('pre_get_posts', array(&$userAccessManager, 'AB_pre_get_posts'));
Now we only need to change the faulty getPostsForUser method by changing class/UamAccessHandler.class.php. Find the method (around line 530), and change the following code:
// MY FIX TO MAKE PAGINATION WORK WITH CUSTOM POST TYPES
// REMOVED:
// $postAssignedToUserSql = "
// SELECT igp.object_id
// FROM ".DB_ACCESSGROUP_TO_OBJECT." AS igp
// WHERE igp.object_type = 'post'
// AND igp.group_id IN (".$userUserGroupString.")";
// ADDED:
$postableTypes = $this->getPostableTypes();
$postableTypesString = "'".implode("','", $postableTypes)."'";
$postAssignedToUserSql = "
SELECT igp.object_id
FROM ".DB_ACCESSGROUP_TO_OBJECT." AS igp
WHERE igp.object_type IN ( ".$postableTypesString." )
AND igp.group_id IN (".$userUserGroupString.")";
For me this did the trick. Be aware that on an update of the plugin, these changes will be lost (although hopefully the problem might be fixed by the update). Hope it works for others too!