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.


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').

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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