I’m trying to echo the results of a field that displays every row that the current post’s category has in common with.
<?php
<!--grabs the current post's categorie's id-->
$thiscat = $wpdb->get_var($wpdb->prepare("
SELECT term_relationships.term_taxonomy_id
FROM $wpdb->posts
LEFT JOIN $wpdb->term_relationships
on $wpdb->posts.id = $wpdb->term_relationships.object_id
WHERE $wpdb->posts = post->id"));
<!--grabs all the rows that has a category id that matches $thiscat-->
$episodelist = $wpdb->get_results("
SELECT post_episode
FROM $wpdb->posts
LEFT JOIN $wpdb->term_relationships
on $wpdb->post.post_id = $wpdb->term_relationships.object_id
LEFT JOIN $wpdb->terms
on $wpdb->term_relationships.term_taxonomy_id = $wpdb->terms.term_id
WHERE $wpdb->terms.name = $thiscat ");
<!--print the results-->
foreach ($episodelist as $episodelist) {
echo $episodelist->post_episode; }
?>
I get no result.