Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

Thanks.

share|improve this question

1 Answer 1

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

 
discard

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.