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:


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


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


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.com/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

| improve this answer | |
  • To be honest I am very bad at rewriting URLs. Is it possible to make any example? It is not necessary to fully solve my problem, it would be great if you can just show the direction I need to move. – Nikolai Maksimov Oct 31 '18 at 8:20
  • I have edited my ans, see for example – Pravin Work Oct 31 '18 at 9:20
  • 1
    Wow, now it looks clear to understand. Thanks for explanation! Great answer. – Nikolai Maksimov Oct 31 '18 at 10:25

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.