1

I have a blog that has a custom post type article, and the link is http://example.com/article/lorem-ipsum.

How can I use add_rewrite_rule to add a new link style to the same post http://example.com/article/lorem-ipsum/readers in such a way that the part readers add a GET parameter &showReaders=true to the page http://example.com/article/lorem-ipsum.

2

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.

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.