In your code this in the condition where you decide when to apply the meta query condition:
if($query->is_main_query()) {
Therefore if the conditions inside there are working sometimes and not others, it means that condition is true when it’s working and not when it’s not.
The solution to this is dependent on all the code running on your site, but first I’d suggest validating this theory by changing this line to the below. Do this on your development environment or temporarily in production if you have to
if(true) {
This means those meta conditions will get applied to every query. Obviously you don’t want that, but if your other paginated pages start working as you want that will confirm this is the problem.
If it is the problem, you just need to find another condition that suits what you need better than is_main_query
. For example is_home
could be what you’re looking for
If that’s not the problem, then something else more complicated is happening on your other paginated pages that’s messing with your queries, or using a different method that’s ignoring these parameters.