Here you’ve did something wrong with $wpdb->table_name
. It will only return the default WordPress table names. Not custom table names. And also when you call $wpdb->prepare
then pass the parameter as array. So your function will be like below-
function get_info($postid) {
global $wpdb;
// Here I assumed that your table name is '{$wpdb->prefix}places_locator'
$sql = $wpdb->prepare("SELECT post_id, address, phone, email
FROM {$wpdb->prefix}places_locator
WHERE post_id = '%d'",
array( $postid )
);
$info = $wpdb->get_results($sql);
return $info;
}
Now if you do print_r
on get_info()
with parameter post ID then it will return you value.
Use like below-
print_r(get_info(1)); // Here I assumed your post ID is 1