WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a page with slug/name charts. So the url looks like http://domain.tld/charts/ for the Charts page. When i type the url to http://domain.tld/charts/(something) or http://domain.tld/charts/(something)/(something), i got error not found, logically it should as there is no sub page with the given names.

Now what is want is, when is visit to http://domain.tld/charts/(something) or http://domain.tld/charts/(something)/(something), it should still query the Charts page, and also add the single or multiple occurred (something) into wp query var so that i can access it with get_query_var function. The (something) would return as an array ofcourse.

The (something) could be any Alphanumeric characters, and not needed to be a valid one. Just need it so that WordPress Still makes query for the Chart page, and all the extra url path are added to wp_query Object.

Your help is strongly needed.

share|improve this question
Have a look at add_rewrite_rule questions and in Codex. – Milo Dec 31 '13 at 0:29
up vote 0 down vote accepted

This should do what you want:

add_action('generate_rewrite_rules', 'wpse128082_add_rewrite_rule');
function wpse128082_add_rewrite_rule($wp_rewrite) {
    $new_rules = array(
        '^charts/(.*)' => 'index.php?pagename=charts&something='.$wp_rewrite->preg_index(1),
    $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;

add_filter('query_vars', 'wpse128082_add_query_var');
function wpse128082_add_query_var($query_vars) {
    $query_vars[] = 'something';
    return $query_vars;

On your Charts page, you can access the new query var with get_query_var('something').

share|improve this answer
I suggest adding rewrite rules via the API: add_rewrite_rule. – Milo Dec 31 '13 at 19:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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