Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've created a bid module that allows the users to bid on an auction through a node reference. I'm using hook_form_alter() to create the form on the 'create bid' page, and I would like to perform some SQL queries dealing with the referenced node.

How do I load the node reference?

share|improve this question

To load a node, use


This requires that the node is saved and that you have it's nid.

To give a better answer more details are needed

share|improve this answer
I'm developing a Drupal module for a client website. The custom content type is called bid. I've created one field using cck that is a node reference. The other fields are generated inside the module using hook_form_alter, hook_form_state etc. On the create bid page the cck field loads the nodereference through the url. Example: example.com/node/add/bid/75. How do I access the referenced node inside my .module file where the form is generated? In other words, how do I load the info (nid, user, path, etc.) for the referenced node within my custom .module script? Thanks for your time. – CarlosM Aug 9 '11 at 21:13
If it's part of the path, you can get it from either the menu() hook, or just grabbing it out of $_GET['q'] or arg(#). api.drupal.org/api/drupal/includes--path.inc/function/arg/6 for more info. In this case it would be arg(3) though. – Jimajamma Dec 12 '11 at 0:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.