Query to display post by category using Joins.
<?php global $wpdb, $post; $slug = get_post( $post )->post_name; $query = "SELECT * FROM wp_posts p LEFT OUTER JOIN wp_term_relationships r ON r.object_id = p.ID LEFT OUTER JOIN wp_term_taxonomy x ON x.term_taxonomy_id = r.term_taxonomy_id LEFT OUTER JOIN wp_terms t ON t.term_id = x.term_id WHERE p.post_status = 'publish' AND p.post_type = 'post' AND t.slug = '$slug' order by ID Desc limit 8"; ?>