Get current node ID
chrism2671 - May 18, 2008 - 10:05
| Project: | Custom filter |
| Version: | 5.x-1.2 |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
$node->nid doesn't appear to be available in the php-code section of the filter. What do you suppose is the best way of getting the nid for the current node? (Might want to reassign this as a feature request)
Awesome module by the way, a real gem.

#1
Hi,
Filters are processed before node object loaded, that's why we couldn't merely use $node object. See issue #229936: Date issue in php-enabled custom filter for details. There a patch in comment #2, or you can copy and paste this code to your customfilter.module
<?php
function customfilter_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
global $_customfilter_code_vars;
if ($op == 'load') {
$_customfilter_code_vars->node = $node;
}
}
?>
In the filter's code, use
$vars->node->nidto get the node's nid, or$vars->nodeto get node object. This patch forces drupal to load node before the filter get processed.Hope it helps.
Thanks for your kind words.
#2
I am setting this support request as fixed because it got an answer. The reported code is the one used in the 6.x-2 branch.
#3
Automatically closed -- issue fixed for 2 weeks with no activity.
#4