I have the following module, which affects how users arrive at two different content types, "question" and "poll". Question is a CCK content type, poll is the default poll content type, but it works perfectly for question, taking a user who goes to, i.e.,
http://sparechangenews.net/content/are-you-seeing-evidence-economic-recovery (which is a "question" content type)
to
http://www.sparechangenews.net/question/270 (with 270 being the NID)
but
http://sparechangenews.net/question/what-would-you-see-more-spare-change-news (which is a poll)
just goes to the normal url. I need that redirect because I have a view that checks the NID (pulling it from the URL) for nodes that references it, and uses them as sort of super comments (ripped from this tutorial). Am I referencing poll wrong in the module? Any tips?
<?php
/**
* @file
* An example module to redirect the path from a node view for at
* specific type to a view.
*/
/**
* Implementation of hook_init().
*/
function example_init() {
// Using arg() instead of menu_get_item(). Rumor has it menu_get_item
// can occassionally cause WSOD.
// We make sure arg(2) is empty so we do not redirect on edit or other
// node sub pages.
if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == '') {
$node = node_load(arg(1));
if ($node->type == 'answer') {
drupal_goto('question/'. $node->field_answer[0]['nid']);
}
elseif ($node->type == 'poll' || $node->type == 'question') {
drupal_goto('question/'. $node->nid);
}
}
}