In hook_node_insert() i have used drupal_goto(), to go to the newly created node with alias name of it, but id doesn't work.
I have already created url alias with patterns for that content type.
$alias = drupal_get_path_alias('node/'.$node->nid);
drupal_goto($alias);
If i give drupal_goto() with nid it works.
drupal_goto('node/'.$node->nid);
What is the issue with respect to alias name not working or how to get alias of newly created node and get it redirected to view page of it with alias name as url.
Any ideas or suggestions? Thanks in advance.
[Updated code]
This is the code which i am trying
function hook_node_insert($node)
{
if($node->type == 'product')
{
$_SESSION['product_node_nid'] = $node->nid;
$banner = $_SESSION['banner'];
$theme = $_SESSION['theme'];
$params = array();
$params['node'] = $node;
$site_email = variable_get('site_mail', '');
if(($banner || $theme) || ($banner && $theme)) {
drupal_goto('payment-approval');
}
else {
//$alias = drupal_get_path_alias('node/'.$node->nid);
module_load_include('inc', 'pathauto'); // include the inc file for Pathauto module
pathauto_create_alias('node', 'insert', 'node/'.$node->nid, array('node' => $node), $node->type, $language->language); // Language is optional
$alias = drupal_get_path_alias('node/'.$node->nid);
//$alias = drupal_get_path_alias('node/'.$node->nid); print_r($alias); exit();
drupal_goto($alias);
}
}
}
node
module to redirect tonode/[nid]
when new node be save. What you want to achieve with your code, its not clear. Please update the complete scenario, so you will find the correct solution.