1

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.

1 Answer 1

0
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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