Someone help me with this wpdb-> sql statement?
-
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.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Someone help me with this wpdb-> sql statement?’ is closed to new replies.