Extending WP_Query — Optimise SQL query

Here’s an idea, however it will require the ability to make custom SQL queries – with $wpdb. Since you want to get posts followed by a user, you can create a view, with the following structure: id user_id post_id post_title post_content … (all other post fields) don’t worry about duplicating posts. When you select, you … Read more

Order wp_query by calculated field

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’ );

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)