【问题标题】:Wordpress pages returns 404 errorWordpress 页面返回 404 错误
【发布时间】:2018-04-03 20:48:21
【问题描述】:

我有一个带有 woocommerce 的 wordpress 设置,我只需要使用以下代码添加从 url 重写的自定义 get 变量:

add_action('init', 'kids_init_wordpress');
function kids_init_wordpress() {


    // Rewrite urls
    add_rewrite_rule(
        'my_project/(.+?)/([^/]*)/page/?([0-9]{1,})/?$','index.php?product_cat=$matches[1]&country=$matches[2]&paged=$matches[3]',
    'top'
);

    add_rewrite_rule(
        'my_project/(.+?)/([^/]*)/?$','index.php?product_cat=$matches[1]&country=$matches[2]','top'
    );

}

使用自定义查询变量

add_filter('query_vars', 'add_query_vars');
function add_query_vars($q) {
    $q[] = 'country';
    return $q;
}

我还为 woocommerce 帖子类型创建了一个名为 country 的自定义分类法。 上面重写的 URL 工作正常,但由于原因,我不知道我的所有页面 URL 现在都已损坏并返回 404 错误。

有人可以帮帮我吗?

更新 =====================

所以我从 新安装的 wordpress + woocommerce

中重现了这个错误

1- 我从 woocommerce 创建了一个新的自定义分类法国家 2- 我在这个新分类中附加了一些产品 3-从“设置>永久链接”刷新网址 4- 现在购物车页面返回 404 页面,不仅是购物车页面,而且是所有 wordpress 页面。

这就是我创建分类的方式:

add_action( 'init', 'create_product_taxonomies', 0 );
function create_product_taxonomies() {
    // Add new taxonomy, make it hierarchical (like categories)
    $labels = array(
    'name'              => _x( 'Regions', 'Régions', 'kids' ),
    'singular_name'     => _x( 'Region', 'Région', 'kids' ),
    'search_items'      => __( 'Chercher une région', 'kids' ),
    'all_items'         => __( 'All Genres', 'textdomain' ),
    'parent_item'       => __( 'Parent région', 'kids' ),
    'parent_item_colon' => __( 'Parent région:', 'kids' ),
    'edit_item'         => __( 'Editer une région', 'kids' ),
    'update_item'       => __( 'Mettre à jour une région', 'kids' ),
    'add_new_item'      => __( 'Ajouter une région', 'kids' ),
    'new_item_name'     => __( 'Nouvelle région', 'kids' ),
    'menu_name'         => __( 'Régions', 'kids' ),
);

$args = array(
    'hierarchical'      => true,
    'labels'            => $labels,
    'show_ui'           => true,
    'show_admin_column' => true,
    'query_var'         => true,
    'rewrite'           => array( 'slug' => '/', 'with_front' => true ),
);

register_taxonomy( 'region', array( 'product' ), $args );
register_taxonomy_for_object_type( 'item', 'product' );
}

【问题讨论】:

    标签: php wordpress url-rewriting woocommerce


    【解决方案1】:

    您是否尝试过从 Wordpress 管理面板恢复永久链接?只需转到永久链接选项并单击保存...

    【讨论】:

    • 是的,我恢复了 100 次,我发现这是 wordpress 或 woocommerce 的错误,如上所述,我使用 woocommerce 创建了新的干净的 wordpress 设置并创建了新的分类法(级别的新分类法woocommerce 类别)用于 woocommerce 和刷新永久链接,这会破坏购物车页面
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-27
    • 2017-05-23
    • 2017-02-03
    • 2020-03-22
    • 2013-05-29
    • 1970-01-01
    • 2020-08-28
    相关资源
    最近更新 更多