POST标签文本重命名获取错误

时间:2017-03-04 作者:Hossain Misho

我试图用此代码重命名我的post标记,但出现以下错误:

注意:未定义的属性:stdClass::/var/www/new/wp admin/includes/class wp posts列表中的$no\\u terms。php在线1107

我的代码:

<?php  

function rename_texonomy_tag()
{
    global $wp_taxonomies;
    $wp_taxonomies[\'post_tag\']->labels = (object)array(
        \'name\' => \'Groups\',
        \'menu_name\' => \'Groups\',
        \'singular_name\' => \'Group\',
        \'search_items\' => \'Search Groups\',
        \'popular_items\' => \'Popular Groups\',
        \'all_items\' => \'All Groups\',
        \'parent_item\' => null, // Tags aren\'t hierarchical
        \'parent_item_colon\' => null,
        \'edit_item\' => \'Edit Groups\',
        \'update_item\' => \'Update Groups\',
        \'add_new_item\' => \'Add new Groups\',
        \'new_item_name\' => \'New Groups Name\',
        \'separate_items_with_commas\' => \'Separata Groups with commas\',
        \'add_or_remove_items\' => \'Add or remove Groups\',
        \'choose_from_most_used\' => \'Choose from the most used Groups\',
    );

    $wp_taxonomies[\'post_tag\']->label = \'Groups\';
}

?>

1 个回复
SO网友:WPExplorer

您需要小心覆盖整个数组,因为WordPress可能会不时添加新项目。。。替代每个特定值,如下所示:

add_action( \'init\', function() {

    global $wp_taxonomies;

    $wp_taxonomies[\'post_tag\']->labels->name = \'Groups\';
    $wp_taxonomies[\'post_tag\']->labels->menu_name = \'Groups\';
    $wp_taxonomies[\'post_tag\']->labels->singular_name = \'Group\';
    $wp_taxonomies[\'post_tag\']->labels->search_items = \'Search Groups\';

    $wp_taxonomies[\'post_tag\']->label = \'Groups\';

}, 1 );
我展示了几个示例,只需对所有希望更改的值执行即可。

相关推荐