• Hi guys, the following is actually making me some kind of a headache currently:

    I have added some custom quer vars and those work fine so far:

    function add_custom_query_vars($vars) {
      $vars[] = "tdhm";
      $vars[] = "tdht";
      return $vars;
    }
    add_filter('query_vars', 'add_custom_query_vars');

    Then I added a custom rewrite rule

    function add_rewrite_rules($aRules) {
      $aNewRules = array('tdh2015/danke/([^/]+)/([^/]+)/?$' => 'index.php?pagename=danke&tdhm=$matches[1]&tdht=$matches[2]');
      $aRules = $aNewRules + $aRules;
      return $aRules;
    }
    add_filter('rewrite_rules_array', 'add_rewrite_rules');

    And made sure, it was activated
    $wp_rewrite->flush_rules( );

    I then tested this rewrite rule with the monkeyman-rewrite-analyzer tool within wordpress and all looks fine so far. But when I try to access the variables within my custom page template, they never seem get populated.

    actually the routing

    “tdh2015/danke/myfirstparam/mysecondparam”

    should translate to:

    page: tdh2015/danke/

    with the local variables

    tdhm: myfirstparam
    tdht: mysecondparam

    available. I tried to access the variables via

    if(isset($wp_query->query_vars['tdhm'])) {
      $tdhm = urldecode($wp_query->query_vars['tdhm']);
    }
    if(isset($wp_query->query_vars['tdht'])) {
      $tdht = urldecode($wp_query->query_vars['tdht']);
    }

    Has anyone here worked successfully with a similar setup?

    Thanks in advance! Cheers, Matt

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

    (@ffpr)

    Ok – I found another article on this topic suggesting to use rewrite tags instead of query vars.

    So I set this up by using

    function custom_rewrite_tags() {
      add_rewrite_tag('%tdhm%', '([^&]+)');
      add_rewrite_tag('%tdht%', '([^&]+)');
    }
    add_action('init', 'custom_rewrite_tags', 10, 0);

    Yet it’s still not working. Any thoughts?

Viewing 1 replies (of 1 total)
  • The topic ‘Custom rewrite rule not translating into custom query vars’ is closed to new replies.