0

Ok, so I've added a custom permalink, which is mapping to my page fine. For some reaosn though the filters I've added aren't showing up. In the shortcode, they're just being returned as NULL.

My code is;

function custom_rewrite( $wp_rewrite ) {
$feed_rules = array(
    'local/(.*?)/(.*?)/?$'  =>  'index.php?page_id=41&trade=' . $wp_rewrite->preg_index(1).'&area=' . $wp_rewrite->preg_index(2),
    'local/(.*?)/(.*?)?$'  =>  'index.php?page_id=41&trade=' . $wp_rewrite->preg_index(1).'&area=' . $wp_rewrite->preg_index(2),
);
$wp_rewrite->rules = $feed_rules + $wp_rewrite->rules;
}

function custom_wp_querystring() {
add_rewrite_tag('%trade%','([^&]+)');
add_rewrite_tag('%area%','([^&]+)');
}
add_action( 'init', 'custom_wp_querystring');
add_filter( 'generate_rewrite_rules', 'custom_rewrite' );

add_shortcode('rewrite_local', 'rewriteShortcode');

function rewriteShortcode() {
echo "vars are";
var_dump($wp_query->query_vars['trade']);
var_dump($wp_query->query_vars['area']);
}

Is it something simple I've missed?

1 Answer 1

0

Maybe in the custom_rewrite function, try concatenating $wp_rewrite->rules and $feed_rules using array_merge, then returning $wp_rewrite.

function custom_rewrite( $wp_rewrite ) {
  $feed_rules = array(
    'local/(.*?)/(.*?)/?$'  =>  'index.php?page_id=41&trade=' . $wp_rewrite->preg_index(1).'&area=' . $wp_rewrite->preg_index(2),
    'local/(.*?)/(.*?)?$'  =>  'index.php?page_id=41&trade=' . $wp_rewrite->preg_index(1).'&area=' . $wp_rewrite->preg_index(2),
  );
  $wp_rewrite->rules = array_merge($feed_rules, $wp_rewrite->rules);
  return $wp_rewrite;
}

I haven't tested that at all, just a suggestion of something to be looking at.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.