WooCommerce自定义重写规则数组-子类别

时间:2017-01-10 作者:a_toohill

在此处使用此代码:

    add_filter( \'rewrite_rules_array\', function( $rules )
{
    $new_rules = array(
        \'services/([^/]*?)/page/([0-9]{1,})/?$\' => \'index.php?product_cat=$matches[1]&paged=$matches[2]\',
        \'services/([^/]*?)/?$\' => \'index.php?product_cat=$matches[1]\',
    );
    return $new_rules + $rules;
} );
还有这些永久链接设置

产品类别库:服务

product permalink-自定义基础:/services/%product\\u cat%

我得到以下信息:

/服务/%category\\u name%/(父产品类别页面工作正常)

/服务/%类别\\u名称%/%子类别\\u名称/(Child Product Category Page does not work - gets 404)

/服务/%类别\\u名称%/%子类别\\u名称/%产品\\u名称(单个产品-正常工作)

有人知道如何让子产品类别页面不抛出404错误吗?

谢谢

1 个回复
SO网友:min0r

Try this

add_filter( \'rewrite_rules_array\', function( $rules )
{
    $new_rules = array(
        \'services/([^/]*?)/page/([0-9]{1,})/?$\' => \'index.php?product_cat=$matches[1]&paged=$matches[2]\',
        \'services/([^/]*?)/?$\' => \'index.php?product_cat=$matches[1]\',
        \'services/([^/]*?)/([^/]*?)/?$\' => \'index.php?product_cat=$matches[2]\'
    );
    return $new_rules + $rules;
} );

相关推荐