0

As you know drupal has a function " node_type_get_types " that we can use to get the type of the node, so is there also a function that we can use to get the nid of the current node that we are viewing?

2 Answers 2

1

it's just a property of the Node itself, the nid of the node. It is the value $node->nid.

EDIT

There is also entity_extract_ids() which is 1 level up from a Node in the object hierarchy and this function interacts with Entities -- if you're trying to do something more generic than merely interact with solely Nodes ... such as a process a Queue of Entity objects all of different types but sharing a field you want set with a certain value.

Helper function to extract id, vid, and bundle name from an entity.

Parameters

$entity_type: The entity type; e.g. 'node' or 'user'.

$entity: The entity from which to extract values.

Return value

A numerically indexed array (not a hash table) containing these elements:

0: Primary ID of the entity.

1: Revision ID of the entity, or NULL if $entity_type is not versioned.

2: Bundle name of the entity, or NULL if $entity_type has no bundles.

0

A little NID trick... (if this is what your talking about)

Go to your Content Manager page and hover over the Edit link on the node. Look down at the bottom of your browser (bottom-left for chrome) and you'll see the NID listed within the url that appears there.

2
  • or just goto the Edit page for any node and look at the URL in the location bar of any browser and stop straining your eyes :)
    – tenken
    Aug 30, 2014 at 1:50
  • Yes... absolutely! But when you're dealing with complex views and need a bunch of nid's from random nodes, it's way easier (on your time - not your eyes) to go to the content manager and just hover over the edit links of the nodes you're looking for. I haven't used it, but I believe views_bulk_operations can be configured to list nid's on the content manager page.
    – JosephRae
    Oct 6, 2014 at 19:29

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.