I just came across this page with almost similar requirements as mine

Multiple endpoints to same page

i have to achieve same functionality but i also want to pass some parameters to the page where all these URL will be map.
say example

http://mysite.com/test/link1
http://mysite.com/test/link2 
http://mysite.com/test/link3 

i want to map them to same URL

http://mysite.com/test/finalDestination

along with it i also want to send some other parameters like

  1. user email
  2. user name

so that i can use them at that page for my custom logic.i know how to do it in JSP/Java where i can send them as a request parameters in POST request and can reterieve them in the final JSP

how i can achieve this is wordpress using php.my prefrences are not to use any query string.

Or is it possible like if i create URL with like

http://mysite.com/test/user1
http://mysite.com/test/user2 
http://mysite.com/test/user3

where user1 etc can be fetched from the database and we can ensure that they will be unique through the application and mapping these URLs to same end point.
how can i fetch the username in my final page?

Thanks in advance

3 Answers
3

You can use the same answer as the question you referred to (I have answered it). Here’s how you would change to pass the arguments:

<?php
    add_action('init', 'add_my_rule');

    function add_my_rule()
    {
        global $wp;
        $wp->add_query_var('args');

        add_rewrite_rule('test\/finaldestination\/(.*)','index.php?pagename=about&args=$matches[1]','top');
    }
?>

Assuming ‘finaldestination’ stays the same always, and the pagename (slug) is ‘about’ (you can change both). Apply your custom template to this page, and on the template, do this:

//if you visit http://.../test/finaldestination/name/romeo, then $params will be name/romeo. You can explode this and get the value.
$params = get_query_var('args');

After you put this code in your file, just go to Settings>Permalinks and hit the save button.
I haven’t tried this, but have used something similar in a recent project and I’m sure it will work.

Leave a Reply

Your email address will not be published. Required fields are marked *