Support » Plugins and Hacks » Get data from table based upon ID queried from other table

  • Hi all! So, I picked up some WordPress theme designing again and I am trying to do something strange. I query for post IDs based upon the postmeta table, but now, using that ID, I want to get data from the post table.

    $query = "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'foo' ";
    $posts = $wpdb->get_results($query);

    […later continued with…]
    foreach($posts as $post) {
    [need to echo title from the post table belonging to the same post ID]

    I could of course query the database again for the post ID but that seems rather an overkill. I guess there’s an other way. So, is this possible and, if yes, how? It’s probably just my lack of knowledge when it comes to sql-queries in php.

    Thanks

  • The topic ‘Get data from table based upon ID queried from other table’ is closed to new replies.