How does filter the_posts work?

First thing, in your code you are using the_post hook but in your question you are asking about the_posts hook, which are two different things.

the_posts gets called just after the posts have been selected from the database and it passes an array of $posts to your function, so you should use that.

as for the_post hook, it gets fired (usually) inside the loop it self which is to late to change any thing (like redirect) and its not a filter hook, but an action hook which means that if you return nothing, its just exiting your function and not effecting the outcome.

Leave a Comment