How to use filter hook “the_posts” with a function that refers to $this?
As you can see in the documentation, the 2nd argument passed to functions hooked to the_posts is the WP_Query object. To access it you need to define the 4th argument of add_filter(), $accepted_args, to 2, so that you can accept it. Then you just need to accept 2 arguments in your function, and use the … Read more