rewrite rules - how to add extra GET parameters to post to url with add_rewrite_rule?

admin2025-06-02  1

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.

Share Improve this question asked Mar 18, 2019 at 10:44 AbozanonaAbozanona 1492 silver badges11 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748797106a313797.html

最新回复(0)