I have a Wordpress site with a plugin in the backend which sets a $_GET
parameter to my pages URL. Now I need to replace the value from this parameter with my custom value but this won't work:
My URL: http://localhost/wordpress/mein-konto/testpage/585/?conversationId=0
On the testpage/585 I've included a PHP file which get loaded on page load. In this file I have this function:
add_query_arg( 'conversationId', 1234, get_permalink() );
Now I'm expecting this URL here:
http://localhost/wordpress/mein-konto/testpage/585/?conversationId=1234
I'm not sure what I'm doing wrong.
Try this:
$conversationId = get_query_var( 'conversationId', '0' )
if ($conversationId === '0')
wp_safe_redirect( add_query_arg( 'conversationId', 1234, get_permalink() ) )
It sounds like you are expecting add_query_arg
to do the redirection, but it does not -- instead, it just returns a string that you can redirect to. So, just put the returned string into a call to wp_safe_redirect
and you are good!
However, before redirecting to the same page you need to check whether the redirection is necessary -- otherwise you'll end up in an endless redirection loop (that your browser will detect and stop).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.