$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>rewrite rules - how to add extra GET parameters to post to url with add_rewrite_rule?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin7PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far