Wordpress prefix dynamic value to custom taxonomy url

£可爱£侵袭症+ 提交于 2019-12-25 03:44:08

问题


I have two custom taxonomies 'edition' and 'features'

I'd like wordpress to allow me to prefix the slug of features with a value from editions.

For example if i go here;

mysite.com/asia/features/interviews/

Wordpress would translate the url to;

mysite.com/index.php?features=interview&edition=asia

and then loading the features taxonomy template where i can then grab the edition query_var and filter the templates accordingly.

I'm thinking playing around with add_rewrite_rule would sort it am not sure.

Any help appreciated

Cheers

UPDATE

Ok I think I'm semi on the right lines, I have a rewrite rule written;

RewriteRule ^(media|asia|uk)/([^/]+/)*(^/)? index.php?feature=$2&department=$1

Which takes a url like;

www.mysite.com/media/features/interviews/face-to-face/

but it converts it to;

index.php?feature=face-to-face/&department=asia

Some how I need to get rid of the last / but I'm not proficient enough in regular expressions to work it out.

any ideas?


回答1:


Solved, the correct rule was;

RewriteRule ^(media|asia|uk)/([^/]+/)*([^/]+)/? index.php?feature=$3&department=$1


来源:https://stackoverflow.com/questions/16251287/wordpress-prefix-dynamic-value-to-custom-taxonomy-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!