I have a blog that has a custom post type article
, and the link is .
How can I use add_rewrite_rule
to add a new link style to the same post in such a way that the part
readers
add a GET
parameter &showReaders=true
to the page .
I have a blog that has a custom post type article
, and the link is http://example/article/lorem-ipsum
.
How can I use add_rewrite_rule
to add a new link style to the same post http://example/article/lorem-ipsum/readers
in such a way that the part readers
add a GET
parameter &showReaders=true
to the page http://example/article/lorem-ipsum
.
You want to use the add_rewrite_endpoint since what you are concerned with is at the end of the URL.
function wpseo331941_reader_endpoint() {
add_rewrite_endpoint('readers', EP_PERMALINK | EP_PAGES);
}
add_action('init', 'wpseo331941_reader_endpoint', 10, 0);
//When you want to check if the 'readers' is being used
if ( false !== get_query_var('readers', false) ){
//....
}
Note that the false !== has to be present, because your query var "readers" will have an empty string as its value.