• Resolved SteveYantz

    (@steveyantz)


    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)
  • Thread Starter SteveYantz

    (@steveyantz)

    If someone could look over it and tell me if I’m doing it correctly, that’d be nice.

    The result should show printed data of the post_episode field’s that have the same category.

    (yes the post_episode field is a field I added, the content in it is numeric)

    Thread Starter SteveYantz

    (@steveyantz)

    nvm… Figured it out myself. Thanks for the help.

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