我正在创建一个自定义旅游和旅游主题,其中我创建了自定义的post类型城市、地点、目的地,并使用自定义permalink结构。/%category%/%postname%/
所以现在我想在城市、目的地或位置名称之前附加一个州名称或地区名称。让我举一个例子来更清楚地说明这一点。
当前的url结构如下所示。http://test.com/custom_post_type_slug/post_name_slug
我希望它是这样的。http://test.com/Custom_dynamic_string/custom_post_type_slug/post_name_slug现在我正在做这样的事情
function add_places_rewrite_tags(){
add_rewrite_tag(\'%district%\',\'([^/]+)\');
}
add_action( \'init\', \'add_places_rewrite_tags\' );
add_action( \'init\', \'custom_rewrite_rules\' );
function custom_rewrite_rules() {
add_rewrite_rule(
"/([^/]+)/hotel/([^/]+)/?",
\'index.php?post_type=hotel&district=$matches[1]&p=$matches[2]\',
\'top\'
);
add_filter( \'query_vars\', \'custom_query_vars\' );
}
function custom_query_vars( $query_vars )
{
$query_vars[] = \'district\';
return $query_vars;
}
但它仍然没有给我想要的结果,我也在使用plugin 分析re-wright规则