ter*_*all 9 php wordpress wpml
我在WPML论坛上提出了这个问题,但希望有人能够提供帮助.
我正在尝试将slug翻译为自定义帖子类型
英文网址是http://brigade-electronics.com/nl/products/backeye360/
翻译的URL应为http://brigade-electronics.com/nl/producten/backeye360/
相反,在启用translate slug选项后导航到URL时出现404错误
复制问题的步骤:
我已在故障排除页面中运行所有选项,以清理数据库.
这似乎只适用于产品部分中的某些页面.最奇怪的部分是网站的加拿大部分,因为术语"产品"是英文的,因此无论是否有翻译的slu,URL都保持不变,但是,我仍然在这些页面上得到404错误.
值得注意的是,所有其他自定义帖子类型都可以正常工作.
自定义帖子类型已以标准方式注册
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' );
Run Code Online (Sandbox Code Playgroud)
根据以下答案,上述代码已更新为
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 );
}
Run Code Online (Sandbox Code Playgroud)
slug的新翻译出现在'String Translation'部分,更新这些字符串时,我得到相同的404错误.如果我把这些作为英语留下,产品部分没有问题.
谢谢
你刷新了重写规则吗?
转到“设置”>“永久链接”并刷新。
注意:如果在插件内注册帖子类型,请在激活和停用挂钩中调用flush_rewrite_rules()(请参阅下面的激活时刷新重写)。如果未使用flush_rewrite_rules(),则您必须手动转到“设置”>“永久链接”并刷新您的永久链接结构,然后自定义帖子类型才会显示正确的结构。
来源: https: //codex.wordpress.org/Function_Reference/register_post_type