• Hi all!

    I’m struggeling with a new plugin I’m writing. I’d like to add a second parameter in the url.

    Example
    https://mysite.com/page/parameter1/parameter2/

    I’ve found the solution for one parameter in this topic but there are no replies on the question how to add +2 custom parameters. I’ve tried this so far:

    function add_gear_var($public_query_vars) {
        $public_query_vars[] = 'myvar1';
    	$public_query_vars[] = 'myvar2';
        return $public_query_vars;
    }
    
    function do_rewrite_test() {
        add_rewrite_rule('gear/([^/]+)/?$', 'index.php?pagename=gear&myvar1=$matches[1]&myvar2=$matches[2]','top');
    }
    
    add_action('init', 'do_rewrite_test');
    
    //and in my function just get the parameters like this:
    function test(){
    $var1 = get_query_var('myvar1');
    $var2 = get_query_var('myvar2');
    
    //doing stuff with var 1 works correct, var2 is still empty, not set so I get the 404 not found page.
    }

    I hope there’s someone out there that knows the answer!

    Thanks in advance!

Viewing 1 replies (of 1 total)
  • Thread Starter crispijn

    (@crispijn)

    Anyone?

    I’ve fine-tuned the rewriterule into this one but this doesn’t solve my problem

    function do_rewrite_test() {
        add_rewrite_rule('gear/([^/]+)/([^/]+)/?$', 'index.php?pagename=gear&myvar1=$matches[1]&myvar2=$matches[2]','top');
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Mutiple parameters in url’ is closed to new replies.