URL Rewrites and Sage

Does sage do anything funky with url rewrites? I’m using an add_rewrite_rule which should be working, but I’m having no luck.

http://wordpress.stackexchange.com/questions/206819/rewrite-rule-for-custom-page-with-query-vars-in-url

Thanks,
Andy.

Just a wild guess, but in your example you use:

add_filter( 'query_vars', 'add_query_vars_filter' );
add_action( 'init', 'listen_rewrite_action' );

Have you tried it with namespaces?

namespace Sage\Rewrites;
add_filter( 'query_vars', __NAMESPACE__ . '\\add_query_vars_filter');
add_action( 'init',  __NAMESPACE__ . '\\listen_rewrite_action' );

More info: https://roots.io/upping-php-requirements-in-your-wordpress-themes-and-plugins/

I manually deleted the .htaccess file and regenerated, which along with the code below, made the rewrite work. The second rewrite rule in the code below makes the pagination work properly.

The .htaccess file doesn’t seem to be getting written with any rules though, but the rewrite is working now anyhow.

  function listen_rewrite_action() {
  add_rewrite_tag('%show%','([^/]*)');
  add_rewrite_rule(
    '^listen/([^/]+)$',
    'index.php?pagename=listen&show=$matches[1]',
    'top');
  add_rewrite_rule(
    '^listen/([^/]+)/page/([^/]+)$',
    'index.php?pagename=listen&show=$matches[1]&paged=$matches[2]',
    'top');
}
add_action( 'init', 'listen_rewrite_action' );

I tried working with a dedicated namespace as advised, but even putting the opening “namespace Sage\Rewrites;” in my functions file started white screening the site.

Thanks,
Andy.