使用Polylang实现自定义文章类型的多语言支持

3
我有一个问题,不知道该如何解决。我们使用Polylang插件使WordPress页面支持多语言。一切都很好,除了其他插件的自定义文章类型。使用此自定义文章类型创建的文章只能加载基础语言(英语)的内容,但是无论我们更改语言,它都无法加载内容。
我是这样注册文章类型的:
register_post_type( 'placement', 
    array(
        'labels' => array(
            'name' => __( 'Placementy' ),
            'singular_name' => __( 'Placement' )
        ),
        'public' => true,
        'menu_icon' => 'dashicons-welcome-write-blog'
    )
);

我尝试在functions.php中注册自定义文章类型,而不是插件主文件,但结果仍然相同...其他自定义文章类型都能正常工作,并且它们也是以相同的方式注册的。我还尝试在我的WordPress主题中为自定义文章类型创建模板,而不是使用插件中的模板,但也失败了...真的不知道为什么它不起作用。特别是当其他所有东西都能正常工作时。在更改后清除了缓存。检查了开发者和本地环境中的更改。是什么原因导致这种行为呢?


“stopped working”是什么意思?你有可以在这里发布的调试输出吗? - vagelis
1个回答

2
在 functions.php 文件中。
    add_filter('pll_get_post_types', 'add_cpt_to_pll', 10, 2);
function add_cpt_to_pll($post_types, $hide) {
    if ($hide)
        // hides 'my_cpt' from the list of custom post types in Polylang settings
        unset($post_types['my_cpt']);
    else
        // enables language and translation management for 'my_cpt'
        $post_types['my_cpt'] = 'my_cpt';
    return $post_types;
}

更多细节请参见https://polylang.wordpress.com/documentation/documentation-for-developers/filter-reference/


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接