我在WPML论坛上提出了这个问题,但是希望这里有人能够提供帮助。
我正在尝试翻译自定义帖子类型的slug
英语URL是http://brigade-electronics.com/nl/products/backeye360/
翻译的URL应为http://brigade-electronics.com/nl/producten/backeye360/
相反复制问题的步骤:
- 单击WPML->翻译选项
- 启用翻译自定义帖子slugs(通过WPML字符串翻译(。
- 在"自定义帖子设置"下(在同一页面上(单击"翻译"复选框
- 为每种语言添加了翻译的sl
- 命中保存
- 导航到前端,仅在产品部分上查看404错误。
我已经在故障排除页面中运行了所有选项,以清除数据库。
这似乎仅适用于产品部分中的某些页面。其中最奇怪的部分是网站的加拿大部分,因为"产品"一词是英文的,因此,在有或没有翻译的slugs的情况下,URL保持不变,但是,我仍然在这些页面上遇到404错误。/p>
也值得注意的是,所有其他自定义帖子类型都没有问题。
自定义帖子类型已以标准方式注册
function register_products_post_type() {
$labels = array(
'name' => __( 'Products', '' ),
'singular_name' => __( 'Product', '' )
);
$args = array(
'label' => __( 'Products', '' ),
'labels' => $labels,
'description' => '',
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_rest' => false,
'rest_base' => '',
'has_archive' => false,
'show_in_menu' => true,
'exclude_from_search' => false,
'capability_type' => 'post',
'map_meta_cap' => true,
'hierarchical' => true,
'rewrite' => array( 'slug' => 'products', 'with_front' => false ),
'query_var' => true,
'menu_position' => 6,
'menu_icon' => 'dashicons-cart',
'supports' => array( 'title', 'thumbnail', 'page-attributes' )
);
register_post_type( 'products', $args );
}
add_action( 'init', 'register_products_post_type' );
根据以下答案,上述代码已更新为
add_action( 'init', 'create_post_type');
function create_post_type() {
$labels = array(
'name' => _x( 'Products', 'general name of the post type' ),
'singular_name' => _x( 'Products', 'name for one object of this post type' ),
);
$args = array(
'labels' => $labels, // An array that defines the different labels assigned to the custom post type
'public' => true, // To show the custom post type on the WordPress dashboard
'supports' => array( 'title', 'thumbnail', 'page-attributes' ),
'has_archive' => true, //Enables the custom post type archive at
'hierarchical' => true, //Enables the custom post type to have a hierarchy
'rewrite' => array( 'slug' => _x('products', 'URL slug')),
);
register_post_type( 'products', $args );
}
slug的新翻译出现在"字符串翻译"部分中,当更新这些字符串时,我会收到相同的404错误。如果我以英语为英文,则产品部分毫无问题。
谢谢
尝试此
add_action( 'init', 'create_post_type');
function create_post_type() {
$labels = array(
'name' => _x( 'Products', 'general name of the post type' ),
'singular_name' => _x( 'Products', 'name for one object of this post type' ),
);
$args = array(
'labels' => $labels, // An array that defines the different labels assigned to the custom post type
'public' => true, // To show the custom post type on the WordPress dashboard
'supports' => array( 'title', 'thumbnail', 'page-attributes' ),
'has_archive' => true, //Enables the custom post type archive at
'hierarchical' => true, //Enables the custom post type to have a hierarchy
'rewrite' => array( _x('slug' => 'products'), 'with_front' => false ),
);
register_post_type( 'products', $args );
}
您是否刷新了重写规则?
转到设置>永久链接和刷新。
注意:如果在插件内注册帖子类型,请致电 flush_rewrite_rules((在您的激活和停用钩中(请参阅 在下面的激活上翻新重写(。如果flush_rewrite_rules((不是 使用,然后您必须手动转到设置>永久链接和 在您的自定义帖子类型将在您的自定义帖子类型之前刷新您的永久链接结构 显示正确的结构。
来源:https://codex.wordpress.org/function_reference/register_post_type