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 1042299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:29:11+00:00 2026-05-16T15:29:11+00:00

I have the following module, which affects how users arrive at two different content

  • 0

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);
    }
  }
}
  • 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-16T15:29:12+00:00Added an answer on May 16, 2026 at 3:29 pm

    I’m not sure what is wrong with your code, but an alternative you might want to check out is http://drupal.org/project/path_redirect in conjunction with https://drupal.org/project/pathauto. You can set up automatic aliases for specific content types and also use path redirect to maintain old alias and redirect to new ones.

    However, I feel like you probably should be able to achieve what you are trying to do without any redirection. If you are just trying to get the nid as a views argument, why not check under “Provide default argument” the “Node ID from URL”, or alternatively check “PHP” and write some custom code like you have above:

    $nid = arg(1);
    

    Regardless, I would recommend tackling the issue with getting whatever you need into views without redirection as it will cut down on the complexity (and overhead).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following simple type: module Structures type Point2D<'T> (x : 'T, y
I have written a module similar to the following: module One class Two def
I have the following lua script : module(modoo,package.seeall) foo=1 bar={12,34} Which works fine using
I have the following code, which has the following two problems: Traceback (most recent
I have the following python code which in my opinion behaves strangely: Imported module:
I have following problem module core contains test utils which is resused in dependent
I have the following Template Haskell code in my module, which is part of
In R I have the following example module which repeats a for loop n
suppose I have a file NecessaryModule.hs, which has the following internals : module NecessaryModule
I have the following code in my Mojolicious application module. When I run this

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.