如何从url中删除分类法

时间:2017-02-15 11:56:38

标签: php wordpress url-rewriting taxonomy custom-taxonomy

我基本上试图从我的网址中删除分类标准,例如: http://www.example.com/posttype/tax/term1/tax/term2

对此: http://www.example.com/postype/term1/term2

我读了很多帖子,说明这是不可能实现的。但是我遇到过许多实现这一目标的网站。所以我问这个问题,希望有人在这里设法实现这一点。

我的重写代码:

function add_query_vars( $query_vars ) {
    $new_vars = array( 'vehicle-type', 'fuel', 'color', 'status', 'gearbox', 'interior', 'exterior', 'safety', 'extra', 'location', 'vehicle-year', 'model' );

    return array_merge( $new_vars, $query_vars );
}
add_filter( 'query_vars', 'add_query_vars' );`
function add_rewrite_rules() {
    global $wp_rewrite;

    $new_rules = array(
        'vehicles/vehicle_status/(.+?)/vehicle_fuel_type/(.+?)/vehicle_color/(.+?)/vehicle_status/(.+?)/vehicle_gearbox/(.+?)/vehicle_interior_feature/(.+?)/vehicle_exterior_feature/(.+?)/vehicle_safety_feature/(.+?)/vehicle_extra/(.+?)/vehicle_location/(.+?)/vehicle_year/(.+?)/vehicle_model/(.+?)/?$' => 'index.php?post_type=vehicles&vehicle_status=' . $wp_rewrite->preg_index(1) . '&vehicle_fuel_type=' . $wp_rewrite->preg_index(2) . '&vehicle_color=' . $wp_rewrite->preg_index(3) . '&vehicle_status=' . $wp_rewrite->preg_index(4) . '&vehicle_gearbox=' . $wp_rewrite->preg_index(5) . '&vehicle_interior_feature=' . $wp_rewrite->preg_index(6) . '&vehicle_exterior_feature=' . $wp_rewrite->preg_index(7) . '&vehicle_safety_feature=' . $wp_rewrite->preg_index(8) .'&vehicle_extra=' . $wp_rewrite->preg_index(9) .'&vehicle_location=' . $wp_rewrite->preg_index(10) . '&vehicle_year=' . $wp_rewrite->preg_index(11) . '&vehicle_model=' . $wp_rewrite->preg_index(12)' ) ;
    }
add_filter('rewrite_rules_array', 'add_rewrite_rules');`

1 个答案:

答案 0 :(得分:-1)

转到设置 - > wordpress面板中的永久链接。根据需要选择永久链接结构。