最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugin development - rewrite URL based on selected taxonomy for post page

programmeradmin0浏览0评论

I have a taxonomy called "group", and their values like "red", "blue", "green" (these are generating dynamic" no any fixed group value.

during post publish I am selecting "Group" for each post. 1 group for each post.

I want to add a rewrite URL for the post if the taxonomy is "red" or "blue" or "green" then the URL of that post should come like

"myweb/red/post-slug-name" or "myweb/green/post-slug-name" or "myweb/blue/post-slug-name" ...

add_action( 'init', 'create_group_tax' );
function create_group_tax() {
    register_taxonomy( 
            'group', 
            'post', 
             array( 'label' => 'Group', 
                    'hierarchical' => true
                )
        );
}

add_rewrite_rule('^red/([^/]*)/?','index.php?group=$matches[1]','top');

also, I want to make it regex rule "'^red/([^/]*)/?'" dynamic with selected taxonomy,this time just to make a test i added it as a static string.

result : Page not found. Nothing here - http://localhost/wordpress/red/my-test/

what do you suggest to do this?

发布评论

评论列表(0)

  1. 暂无评论