I am trying to return found_posts value minus the offset and I am not getting the expected pagination.
function homepage_offset_pagination( $found_posts, $query ) {
//Define our offset again...
$offset = 3;
//Ensure we're modifying the right query object...
if( $query->is_home() ) {
$found_posts = $found_posts - $offset;
}
return $found_posts;
}
add_filter( 'found_posts', 'homepage_offset_pagination', 10, 2 );
When the function tries to subtract $offset from $found_posts, I do not get the correct pagination, however if I echo the value out before returning I get the correct value.
Also, if I substitute $found_posts - $offset with an int literal I do get correct pagination.
I don't know what I am doing wrong.
I would appreciate any help, thanks.
EDIT Removed the is_paged condition because that was removing pagination in the admin panel. This works that same without the bug.
return ($found_posts - $offset);
instead although it seems not necessary according to php.net? Or did you try to put the result into a varaible and return that variable? If the value is right, it should be the same.gettype()
to examine the type of variable? Just try to understand in different perspective.$found_posts - $offset
doesn't work and neither does$found_posts - 3
, but$found_posts - 4
works, but this is an incorrect number to use.