Gravity Forms – gform_field_value – query custom table breaks functions.php

Add this line, before using $wpdb:

global $wpdb;

In the line:

$item_info = $wpdb->get_row("SELECT * FROM fm_household WHERE k_RecordNum='$id'");

in WHERE clause, k_RecordNum is being compared to '$id' string, not to the string value of $id parameter. Change this line to:

$item_info = $wpdb->get_row("SELECT * FROM fm_household WHERE k_RecordNum='{$id}'");

It is very important to check, if your result ( $item_info ) is, in fact, an object. Replace this line:

return $item_info->HomeCity;

with:

if(is_object($item_info)) {
    return $item_info->HomeCity;
} else {
    return $value;
}