Is a permastruct possible on pages?

Since a couple of weeks I’m trying to create my own rewritings on pages. I read a lot about rewriting with posts and custom post-types.

BUT: I have pages that I call with variables. How is it possible to bring these variables into a permalink-structure?

Read More

Currently, I have:

www.mysite.com/pagename/?arg1=value1&arg2=value2

but I want to have something like

www.mysite.com/pagename/value1/value2

I have fount the hook post_link which seems to be used on pages and page_link for pages. But page_link doesn’t work in the same way. How can I do, what I want to do?

Please help!

Related posts

1 comment

  1. Yes this is possible using the $wp->add_query_var function used together with add_rewrite_rule .
    Here you have an example:

    Passing and retrieving query vars in wordpress

    If you want more help here is a cut from one of my old plugins:

    function createRewriteRules() {
            global $wp_rewrite;
    
    
     $new_rules = array(
                    '(.?.+?)/(stenskott)$' => 'index.php?pagename='.$wp_rewrite->preg_index(2).'&ort='.
                    $wp_rewrite->preg_index(1),
                    '(.?.+?)/(bilclas)$' => 'index.php?pagename='.$wp_rewrite->preg_index(2).'&ort='.
                    $wp_rewrite->preg_index(1),
                    '(.?.+?)/(inbrott-i-bil)$' => 'index.php?pagename='.$wp_rewrite->preg_index(2).'&ort='.
                    $wp_rewrite->preg_index(1),
                    '(.?.+?)/(om-glas)$' => 'index.php?pagename='.$wp_rewrite->preg_index(2).'&ort='.
                    $wp_rewrite->preg_index(1),
                    '(.?.+?)/(kontakt)$' => 'index.php?pagename='.$wp_rewrite->preg_index(2).'&ort='.
                    $wp_rewrite->preg_index(1)
            );
           // Always add your rules to the top, to make sure your rules have priority
            return $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
    
    }
    add_action('generate_rewrite_rules', 'createRewriteRules');
    
    function query_vars($public_query_vars) {
    
            $public_query_vars[] = "ort";
    
            return $public_query_vars;
    }
    add_filter('query_vars', 'query_vars');
    
    add_action('init', 'add_endpoints');
    function add_endpoints()
    {
        add_rewrite_endpoint('ort', EP_PAGES);
    }
    

Comments are closed.