How to return value from sql and display it

If you need to return one value then use get_var instead of get_row. get_var will return a string. get_row will return an array or object. $spr_liczbe_wodo = $wpdb->get_var (“select liczba_wodo from wp_ow_adres where adres=”Street 12/6″”); var_dump($spr_liczbe_wodo); The problem with your code, by the way, is that $spr_liczbe_wodo is an object, but when you loop over … Read more

Divide WP_Query posts by date & post type

The post_type isn’t really a meta query – therefore, both of these post_types would at least 1 category added/queried in order to get the filter invoked – using plain SQL is still a last resort. add_filter( ‘posts_groupby’, ‘my_posts_groupby’ ); function my_posts_groupby($groupby) { global $wpdb; $groupby = “{$wpdb->posts}.post_date”; return $groupby; } According to your example (I’d … Read more

Pagination always adding “Next” link when results come from Custom Post Type WP_query

/doctors/ is a post type archive, so we can check if that query is being run in the pre_get_posts action via the conditional tag is_post_type_archive( ‘doctors’ ) and modify those queries accordingly. WordPress passes the query object to the function by reference ( $query in this example ), so we can modify the query vars … Read more