Is there any difference between hooks posts_where with posts_join and posts_search performance wise?

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 … Read more

Prevent pre_get_posts filter on specific post type

Improve your conditional to include a check for post type being queried. It can be done via WP_Query::get method So, where you have if ( !is_admin() ){ $query->set( ‘meta_key’, ‘_ct_selectbox_52f65ae267764’ ); $query->set( ‘meta_value’, $city ); return; } replace with if ( ! is_admin() && in_array ( $query->get(‘post_type’), array(‘event’,’venue’) ) ) { $query->set( ‘meta_key’, ‘_ct_selectbox_52f65ae267764’ ); … Read more

How to modify posts_where filter only for the search query

Problem: The problem with your current snippet is that you are just checking the global main query object, no matter what the current query object is. Workaround: Note that the second input argument for the posts_where filter callback, is the current query object. Use that to determine if it’s the main search query on the … Read more