Custom query incorrectly returning everything [closed]
Custom query incorrectly returning everything [closed]
Custom query incorrectly returning everything [closed]
Using WP_Query, you can order the results by meta_value_num: $args = array ( ‘post_type’ => ‘clinica’, ‘meta_key’ => ‘distance_field_name’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘DESC’ );
You could do two things: A) replace the search with a SQL query that only searches the postmeta table (faster as there’s no JOIN involved – you can get the post via it’s ID later on, when displaying the results). B) Split the string right after WHERE 1=1 and drop the later part. You can … Read more
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
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
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