$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'); ?>url rewriting - How do I rewrite URL that has custom parameter|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)

url rewriting - How do I rewrite URL that has custom parameter

matteradmin8PV0评论

I'm stuck on rewriting my url. been searching for days hacking code together but to no avail - So looking for help now.

My url is:

/?type=newsletter

I want the URL to be:


("topic" is a custom taxonomy)

This post seemed the most concise but couldn't get it to work

Help getting this working would make my day.

I'm stuck on rewriting my url. been searching for days hacking code together but to no avail - So looking for help now.

My url is:

https://domainname/topic/ux-process/?type=newsletter

I want the URL to be:

https://domainname/topic/ux-process/type/newsletter

("topic" is a custom taxonomy)

This post seemed the most concise but couldn't get it to work

https://code.tutsplus/articles/custom-page-template-page-based-on-url-rewrite--wp-30564

Help getting this working would make my day.

Share Improve this question edited Nov 20, 2018 at 10:21 Max Stanworth asked Nov 19, 2018 at 21:33 Max StanworthMax Stanworth 32 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You can use a rewrite endpoint for this.

The first step is to give your custom taxonomy an endpoint mask when you register the taxonomy:

$args = [
    'rewrite' => [
        'slug' => 'topic',
        'ep_mask' => EP_CATEGORIES
    ],
    // the rest of your args...
];
register_taxonomy( 'topic', array( 'post' ), $args );

The next step is to add the endpoint. This should be hooked to run on init, just like your taxonomy registration code.

add_rewrite_endpoint( 'type', EP_CATEGORIES );

Don't forget to flush rewrite rules after adding this code. The easiest way to do this is by visiting the Settings > Permalinks page.

You should now be able to add type/newsletter onto the end of your taxonomy links. To access the passed value, use get_query_var:

$type = get_query_var( 'type', false );

If the code currently expects to find type in $_GET['type'] and you can't change that, you can manually set that value before the code that tries to access it:

$_GET['type'] = get_query_var( 'type', false );
Post a comment

comment list (0)

  1. No comments so far