Show 2 content types in a view that share same field value Hi i have 2 content types:


Agent
Organisation


they both have fields for id:


ID ( agent content type)
Org ID ( Organisation content type)


Now i need to create a view that will list fields from both of the content types, and only relation between them is same value in fields ( field_id and field_org_id ). 

Since content is already there and there are more than 200 nodes in each content type, i need to work with what i have. That means i cant add new fields ( like node reference ).

Is there a way to make a view that will list fields from two content types that share same value in 2 fields with different name? And in each row to have mix of fields from both content type with relation of this ID.
Since field_id and field_org_id are two separate fields, you'll need some way to tie them together. A custom entity could do that, but you could also cheat a little and use a taxonomy vocabulary that contains these two fields.

You could then build a view that displays all content and add a relation to the vocabulary and restrict the results to only the content that possesses this relationship.

Cheaty, but I think it might be the easiest solution.

Edit:

I wouldn't modify the content or content types, but rather, add the field_id and field_org_id fields to the taxonomy vocabulary, then iterate through your Agent and Organization nodes and generate taxonomy terms that associate one field's value to another by populating each term's field_id and field_org_id fields from their respective Agent and Organization nodes.

So, some code...

Create the vocabulary

$vocab = new stdClass();
$vocab-&gt;name = 'Organization to Agents';
$vocab-&gt;machine_name = 'org_to_agents';
taxonomy_vocabulary_save($vocab);


Add the fields

$fields = array(
    'field_id',
    'field_org_id',
);

foreach($fields as $field) {
  // Replace my)taxonomy_vocabulary with your chosen vocabulary name.
  if (is_null(field_info_instance('taxonomy_term', $field, 'my_taxonomy_vocabulary'))) {
    field_create_instance(array(
      'label' =&gt; $t($field),  // &lt;-- This doesn't need to be pretty.
      'widget' =&gt; array(
        'type' =&gt; 'textfield',
      ),
      'field_name' =&gt; $field,
      'entity_type' =&gt; 'taxonomy_term',
      'bundle' =&gt; 'my_taxonomy_vocabulary',
    ));
  }
}


Get the list of IDs

// Credits to https://www.drupal.org/node/1079616#comment-10864932 for example.
$agents = db_query("SELECT nid FROM {node} WHERE type = :type", array(':type' =&gt; 'agent'))
  -&gt;fetchCol();
$orgs = db_query("SELECT nid FROM {node} WHERE type = :type", array(':type' =&gt; 'organization'))
  -&gt;fetchCol();

// Should result in a list of unique Node IDs that exist in
// at least one node for both content types.
$nids = array_intersect($agents, $orgs);


Create your taxonomy terms

$vocab = taxonomy_vocabulary_machine_name_load('my_taxonomy_vocabulary');
foreach($nids as $key =&gt; $nid) {
  $term = (object)array(
    'name' =&gt; $key, // Use any unique value that makes sense here.
    'vid' =&gt; $vocab-&gt;vid,
  );
  $term-&gt;field_id[LANGUAGE_NONE][0]['value'] = $nid;
  $term-&gt;field_org_id[LANGUAGE_NONE][0]['value'] = $nid;
  taxonomy_term_save($term);
}


Again, this is a bit "cheaty", and a custom entity would probably be considered more proper, but I think this should help.

Hope it helps!