• Resolved foo bar

    (@nielshackius)


    Hello,
    what I would like to do is adding a rewrite-rule that redirects me to a certain wordpress-page and passes an additional variable, like this:

    WORDPRESS/index.php/singapore/hello

    –> index.php?page_id=67&gallery=hello

    Thats what I do now:
    add_action('rewrite_rules_array',array($this,'singaporeRewriteRules'));

    function singaporeRewriteRules($rewrite)
    {
    global $wp_rewrite;
    // add rewrite tokens
    $keytag_token = '%gallery%';
    $wp_rewrite->add_rewrite_tag($keytag_token, '(.+)', 'page_id='.get_option('singapore_page').'&gallery=');
    $keywords_structure = $wp_rewrite->root ."singapore/$keytag_token";
    $keywords_rewrite = $wp_rewrite->generate_rewrite_rules($keywords_structure);
    return ( $rewrite + $keywords_rewrite);
    }

    This is what I get in the rewrite_rules_array:

    [index.php/singapore/(.+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?page_id=67&gallery=$matches[1]&feed=$matches[2]

    [index.php/singapore/(.+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?page_id=67&gallery=$matches[1]&feed=$matches[2]

    [index.php/singapore/(.+)/page/?([0-9]{1,})/?$] => index.php?page_id=67&gallery=$matches[1]&paged=$matches[2]

    [index.php/singapore/(.+)/?$] => index.php?page_id=67&gallery=$matches[1]

    Well, nice, but it doesn’t work. What do I do?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter foo bar

    (@nielshackius)

    No ideas? :-[

    This thread might help out, it helped me. Especially the part about refreshing wp_rewrite option!

    Are adding rewrite rules or concatenating? return($rewrite + $keywords_rewrite) looks funny. Shouldn’t it be return($rewrite . $keywords_rewrite) ?

    Thread Starter foo bar

    (@nielshackius)

    You do this because you combine two arrays, rather than two strings kategasis.

    And thank you qrof..I will read this and if it helps I will post a solution.

    I found that in order to receive extra variables over GET that I had specified in a rewrite, I had to specify them as “safe” query variables like so:

    add_filter('query_vars', 'add_my_safe_query_vars');

    function add_my_safe_query_vars($original_vars)
    {
    $extras = array('foo', 'bar');
    return array_merge($original_vars, $extras);
    }

    You can then access them as get_query_var('foo') etc.

    Thread Starter foo bar

    (@nielshackius)

    Okay, the solution was more or less my own stupidity. You don’t get the variables like you might expect in $_POST, $_GET or $_REQUEST. You have to include them as a global.

    For the example I started out with it would be

    function xyz()
    {
    global $gallery;

    //...
    }

    And also sargant was completly right – don’t forget that!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom Permalink structure’ is closed to new replies.