WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to match a posts meta_key value to a separate tables column ID and call that row/array in the single-listing.php.

I have a meta_key value that is called dot_number. The table is called wp_csadata and has a column called dot_number.

Lets say the meta_key equals 12. I need to call that wp_csadata table and match the meta_key value of 12 to the column called dot_number, which has the same number, and return values in the row.


share|improve this question
global $wpdb;

/* grab meta value, it is assumed you know the post id ($id) in question */
$dot_number = get_post_meta( $id, 'dot_number', true );

/* grab all rows with matching value in 'dot_number' column */
$matches_query = $wpdb->get_results(
    "SELECT * FROM " . $wpdb->prefix . "csadata " .
    "WHERE dot_number = " . $dot_number, ARRAY_A

// do something with query result, usually iterate over it and display something
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.