admin管理员组文章数量:1130349
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 badges1 Answer
Reset to default 2for 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')
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 badges1 Answer
Reset to default 2for 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')
本文标签: permalinksHow can I add dynamic page url in WordPress
版权声明:本文标题:permalinks - How can I add dynamic page url in WordPress? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749218117a2334505.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论