如何设置我的自定义邮政类型的‘公司’不同的网址,如果该公司有多个地点。
例如: CPT:" Company“和http://example.com/company CPT公司邮政:”公司ABC":http://example.com/company/company-abc
我有cmb2 (定制的metabox 2)添加收集与一些地点: locations1 -美国,locations2 -英国等。
如果我输入adres url,我想显示位置地址:
美国元地点如果url http://example.com/company/parmeter/1英国元定位如果url http://example.com/company/parmeter/2
我怎样才能做到这一点?
发布于 2018-01-11 19:34:23
您可以使用新的重写规则添加一个参数,如下所示:
add_action("init", function () {
add_rewrite_tag("%countryName%", "([^&]+)");
add_rewrite_rule(
"^company/([^/]*)/country/([^/]*)/?"
, 'index.php?company=$matches[1]&countryName=$matches[2]'
, "top"
);
});添加此代码后,刷新WordPress的重写规则。
然后可以使用像http://example.com/company/company-abc/country/UK这样的URL,然后在模板中使用get_query_var("countryName", NULL)检索参数
https://wordpress.stackexchange.com/questions/290832
复制相似问题