Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6662567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:24:12+00:00 2026-05-26T02:24:12+00:00

I have a node Bug/Requests which references one Project. On the project node page,

  • 0

I have a node “Bug/Requests” which references one “Project”.

On the project “node” page, I would like to display a list of bugs/requests which link to that project. Is this possible?

here is how I ended up doing it:

Is this good or bad? Is there a better way? (in template.php)

<?php
function digital_preprocess_node(&$vars)
{
    $node = $vars['node'];

    if ($node->type == 'project' ) 
    {
        $bugs_requests_nids = array();
        $query = 'SELECT entity_id FROM field_data_field_project WHERE field_project_nid = :project_nid';
        $result = db_query($query, array(':project_nid' =>$node->nid));
        foreach($result as $row)
        {
            $bugs_requests_nids[] = $row->entity_id;
        }

        $vars['tasks'] = node_load_multiple($bugs_requests_nids);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:24:12+00:00Added an answer on May 26, 2026 at 2:24 am

    I think you want the References Module (provides node and user reference fields for Drupal 7)

    Apologies I didn’t read properly, you also want the Corresponding node reference module which makes the node reference bi-directional (D7 versions of the modules given in another answer).

    EDIT to address your new code:

    I’m guessing you’re pretty new to Drupal from your recent questions but either way you’ve hit on (in my opinion) the best method to do this. If you’re comfortable writing PHP code (which a lot of Drupal users aren’t) then grabbing the data directly will always be more efficient than using a contributed module that might have a lot of overhead.

    A few minor points:

    1. I’d consider moving your code out of the template file and into a custom module, inside a hook_node_load function instead so this data is available throughout the life of the nodes (that way you can re-use it in many different contexts). However if you don’t need to reuse this data anywhere except in the template file then it’s fine where it is.
    2. If you’re going to go directly into the field tables you should probably use the field_revision_field_x tables instead of field_data_field_x so you can take advantage of the revision system and always grab the most recent data.
    3. As fields can be attached to multiple entity types you should make sure you’re getting the right field data for the right entity (you may not plan to attach this field to any other nodes/entities but it’s good practice in case you do).

    This is a slightly edited version of your code taking into account the proper field types (untested but should work):

    function digital_preprocess_node(&$vars) {
      $node = $vars['node'];
    
      if ($node->type == 'project' ) {
        $bugs_requests_nids = db_select('field_revision_field_project', 'p')
          ->fields('p', array('entity_id'))
          ->condition('entity_type', 'node')
          ->condition('bundle', 'project')
          ->condition('entity_id', $node->nid)
          ->condition('revision_id', $node->vid)
          ->execute()
          ->fetchCol();
    
        $vars['tasks'] = node_load_multiple($bugs_requests_nids);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 nodes: Project Bug A project has node references to Bugs When
I have a base class Node which contains a list of child nodes. Node
I may have found a Subversion bug, and I would like to make sure
In the sitemap file, I have sitemap Node URL which have more than 1
Alright I have an xml document that looks something like this: <xml> <list> <partner>
I wrote a quick generic linked list, simple stuff. But I have a bug
I have an unformatted telephone number string (5551234567). I would like to format this
I have a node with many CCK fields. I want to hide a field
EDIT: I also have access to ESXLT functions. I have two node sets of
I have a 3-node web farm being managed by IIS7 and Application Request Routing.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.