Redirect to custom ...
 
Notifications
Clear all

Paid Addons Support Forum Only

Please note, that here we only support Paid Addons issues and questions.

gVectors Support staff works from 6am to 6pm (GMT+0)

All questions related to wpForo and wpDiscuz free plugins should be asked in the corresponding plugin support forum:

 

wpDiscuz Support Forum wpForo Support Forum

Redirect to custom URL


sasostebe
(@sasostebe)
New Member
Joined: 2 years ago
Posts: 3
Topic starter  

Hello!
I'm bringing a variable to the comment form (hidden field), let's call it $custom_id.
I am trying to redirect user to custom URL after posting, including this custom id. I found this code on your support:

    public function redirect() {
$messageArray = array('code' => 0);
$commentId = isset($_POST['commentId']) ? intval($_POST['commentId']) : 0;
if ($this->optionsSerialized->redirectPage && $commentId) {
$comment = get_comment($commentId);
if ($comment->comment_ID) {
$messageArray['code'] = 1;
$messageArray['redirect_to'] = get_permalink($this->optionsSerialized->redirectPage);
}
}
$this->commentsArgs['caller'] = '';
wp_die(json_encode($messageArray));
}

I tried replacing this line:

$messageArray['redirect_to'] = get_permalink($this->optionsSerialized->redirectPage);

With this:

$messageArray['redirect_to'] = 'mydomain.com/?p=' . $_POST['custom_id'];

But it's not working. It redirects to mydomain.com. Any ideas?


Quote
sasostebe
(@sasostebe)
New Member
Joined: 2 years ago
Posts: 3
Topic starter  

Another problem I'm facing is that this redirection is taking too much time - i would like to redirect user as soon as possible after hitting the send button.

So I tried making a redirect in addComment() function, but that's not working either...

Is there a better way?


ReplyQuote
sasostebe
(@sasostebe)
New Member
Joined: 2 years ago
Posts: 3
Topic starter  

All problems solved by adding relocation to Submit button 🙂

onclick="location.href = '?p=<?php echo $custom_id; ?>';"

ReplyQuote
Astghik
(@astgh)
Support Team Admin
Joined: 4 years ago
Posts: 5060
 

@sasostebe

Thank you for using wpDiscuz and for contacting us.

Our developers checked your solution. They may suggest another more convenient solution for you. If you decide to use the solution provided by us follow the steps:

1. Put the following code in the active theme functions.php file:

add_filter('wpdiscuz_comment_post', function ($response) {
   $response["callbackFunctions"][] = "customRedirect";
   return $response;
});

2. Below is provided the javascript code, that should be added in your active theme js files and you'll just need to add your custom redirect js code:

wpdiscuzAjaxObj.customRedirect = function () {};

ReplyQuote
galewinston
(@galewinston)
New Member
Joined: 2 years ago
Posts: 1
 
Posted by: @sasostebe

onclick="location.href = '?p=<?php echo $custom_id; ?>';"

Use  window.location.replace('http://w3c.com');

It’s better than using window.location.href = 'http://w3c.com';

Using replace() is better for redirect, because it does not keep the originating page in the session history, meaning the user won’t get stuck in a never-ending back-button fiasco.


ReplyQuote
Share:
Scroll to top