I'm bad with words, so hopefully I can get this across clearly. I'm using Views and the dRealty module. I've tried using relationships, and it's a no go.

I made a Views block of an "Agent" content type that has an agent_id (field_agent_id) text field. The dRealty module creates listings by pulling data from a RETS server, and the agent id (field_listing_agent_id) comes through as a text field. I need to show the data of the agent with the id that matches the listing on the node. How can I pass the field from the node into the Views block?

I'm using Views PHP to filter and I'm referencing How to Filter view by comparing 2 fields, but no luck.

2 Answers 2


The way I've typically seen that type of thing done is using Contextual filters (formerly called "Arguments" in Drupal 6). The Drupal 7 Advanced Views Tip: Contextual Filters screencast or this tutorial on Using Views Contextual Filters should provide a starting point for using them. In short, contextual filters are like regular filters, except that they allow arguments to be passed in dynamically rather than the filter criteria having to be statically set ahead of time.

  • It's a little different. I'm comparing two text fields, one of which I don't have access through the Views (dRealty is weird). I've used Contextual Filters before, but it's just trying to get the data from the node into the query. Right now I'm trying to use hook_views_query_alter, so I'll see how that goes. Thanks for the answer, let me know if you have any other ideas though. Commented Jan 10, 2013 at 5:40

After having no luck with EVA (Entity Views Attachment) as well, I ended up using hook_views_query_alter.

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

  if ($view->name == 'agent_directory' && $view->current_display == "agent_connect") {

        $entity_type = "drealty_listing";
        $entity = menu_get_object($entity_type);
        $agent_id = $entity->field_listing_agent_id['und'][0]['value'];

        if (isset($query->where[1]['conditions'][2]['value'])) {
            $query->where[1]['conditions'][2]['value'] = $agent_id;

I had to grab the dRealty entity from the page, grab the field value I needed, and change the query before running. If anyone has any code suggestions to this, let me know. I'm still open to getting better at this!

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.