Problem
I want to rewrite my GET-variable to /demo/.
My current permalink structure:
/my-new-post/?demo=true
What I want:
/my-new-post/demo/
I have this code:
It allows the “demo” $_GET variable and then echo “true”. It works, just the rewrite part left.
<?php
add_filter('query_vars', 'queryvars' );
add_action('parse_query', 'echo_query_var');
function queryvars( $qvars )
{
$qvars[] = 'demo';
return $qvars;
}
function echo_query_var() {
echo get_query_var('demo');
}
?>
Additional information
- It should work with all posts (not just “my-new-post”).
- It should not return 404.
- I should be able to get the post ID.
- GET variable “demo” can be true, or empty. Not important.
This works so far…