I'm using the following code so that I can search by a field when using node reference. However when I go to save I get the error

this post can't be referenced

function flat_view_views_query_alter(&$view, &$query) {

    if ($view->name == 'ref_flats') {
        // Remove the original title constraint
        unset($query->where[0]['clauses'][1]);
        // Duplicate the argument (keyword to search for), so
        // it is passed to both the title and the other field
        $query->where[0]['args'][] = $query->where[0]['args'][1];

        // Add the custom where clause
        $view->query->add_where(0, "(node.title LIKE '%%%s%%' OR node_data_field_flat_code.field_flat_code_value LIKE '%%%s%%')");
    }
}