5

I want to know which filter hook I should use that performs faster.

I did try both several times and I noticed that posts_search is a bit faster than using the combination of posts_where and posts_join

What is your take on this?

2

All of these hooks are called in a similar fashion and get passes similar data. Under normal circumstances there should be no meaningful performance difference between them.

One scenario I can think of is that if you aren't properly targeting your code to specific queries and it runs in every query then posts_search might fire less time, because other two are conditional on suppress_filters in query being disabled.

  • Yes indeed, I have seen the other two fire more times than posts_search. How can I avoid this? And what do you mean by "properly targeting your code to specific queries?" – Gixty Dec 28 '14 at 19:04
  • @Gixty first thing you should do in your filter is checking if you want it to modify this specific query being filtered. If this is done properly the performance impact shouldn't be noticeable. – Rarst Dec 28 '14 at 19:14
  • Do you mean like this? if ($query->is_search()) – Gixty Dec 28 '14 at 19:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.