title: Get values from a custom table in wordpress using post meta
body: <p>Im a little new to this kind of PHP / Query so please cut me some slack lol. </p>
  
  <p>I have the following.</p>
  
  <p>Post type called $event and a plugin that manages $events. Long story short the locations for events are stored in a custom table. Each event has a post meta "_location_id" which corresponds to the row ID in wp_em_locations table. </p>
  
  <p>I can get the _location_id using:</p>
  
  <pre><code>get_post_meta($eventID, '_location_id', true);
  </code></pre>
  
  <p>However I have no idea how to proceed when it comes to getting values from the different columns that correspond to the row ID in the custom table.</p>
  
  <p>My purpose is displaying a list of events with the location name next to it. </p>
  
  <p>Im now trying the code from below with an edit for the unique id column name and the column name Im looking to get data from and Im returning nothing. </p>
  
  <pre><code>&lt;?php
  global $wpdb;
  $location_id=get_post_meta($eventID, '_location_id', true);
  echo $location_id;
  //the above returns the correct row ID                                          
  $locations=$wpdb-&gt;get_results('select {location_name} from `' . $wpdb-&gt;prefix . 'em_locations` where `location_id`=\'' . $location_id . '\'', ARRAY_A);
      if (!is_null($locations) &amp;&amp; count($locations) &gt; 0){
      foreach ($locations as $location){
      echo $location['location_name'];
      }
      } else {
      //no locations
      } ?&gt;    
  </code></pre>
  
  <p>@Flyer's example didt work for me so I thought perhaps I was doing something wrong so checked up on the codex and went with the following.</p>
  
  <pre><code>global $wpdb;
     $location_id=get_post_meta($eventID, '_location_id', true);
     $myrows = $wpdb-&gt;get_results( 'SELECT location_id, location_name FROM wp_em_locations WHERE location_id = '. $location_id );
     var_dump($myrows);
     /* gives the following
     array(1) { [0]=&gt; object(stdClass)#215 (2) { ["location_id"]=&gt; string(1) "5" ["location_name"]=&gt; string(9) "Liverpool" } }*/
     echo $myrows["location_name"];
     //shows nothing
  </code></pre>