$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'); ?>permalinks - How can I add dynamic page url in WordPress?|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)

permalinks - How can I add dynamic page url in WordPress?

matteradmin8PV0评论

I have a custom post type News.

Also I have added page with front-end post edit.

At this moment I can edit my news by opening this url:

host/edit-news/?id=21231

I want to make a page with url looks like with dynamically changing id of post:

host/news/21231/edit

Where I need to make changes, to make an ability for adding this url to my specific page in WordPress?

I have a custom post type News.

Also I have added page with front-end post edit.

At this moment I can edit my news by opening this url:

host/edit-news/?id=21231

I want to make a page with url looks like with dynamically changing id of post:

host/news/21231/edit

Where I need to make changes, to make an ability for adding this url to my specific page in WordPress?

Share Improve this question asked Oct 30, 2018 at 22:30 Nikolai MaksimovNikolai Maksimov 331 silver badge3 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

for this you will need to be familiar with rewrite URLs.

This results can be achieved by rewrite URL.

Here news will be page and postid and action will be query strings internally.

Here you can find some tutorials of rewrite URLs in WordPress.

For an example http://example/news/?edit=100 is the URL lets make prety.

/**
 * Add rewrite tags and rules
 */
function myplugin_rewrite_tag_rule() {
    add_rewrite_tag( '%news%', '([^&]+)' );
    add_rewrite_rule( '^news/([^/]*)/?', 'index.php?id=2&actionpostid=100&action=edit','top' );
}
add_action('init', 'myplugin_rewrite_tag_rule', 10, 0);

here id=2 is the page id of news page and other parameters are custom.

To retrieve values you will need to add those attributes in the WordPress.

add_filter('query_vars', function($vars) {
   $vars[] = "actionpostid";
   $vars[] = "action";
   return $vars;
});

and retrieve those variables through the

get_query_var('actionpostid')
get_query_var('action')
Post a comment

comment list (0)

  1. No comments so far