更改自定义帖子类型的帖子URL中的插件

时间:2016-03-01 作者:renathy

我已向注册了自定义邮件类型\'has_archive\' => \'gallery\'. 参观时效果很好mysite.com/gallery/ 它将打开存档vmgallery。php,它工作得很好。

然而,我希望vm gallery的帖子也有slug“gallery”。相反,wordpress在表单中生成URLmysite.com/vmgallery/post-slug, 因此使用“旧”自定义帖子类型(vmgallery) 在URL中,而不是在新URL中(gallerymysite.com/gallery/post-slug). 如何修复它?

$labels = array(
            \'name\' => __(\'VmGallery\', THEME_TEXT_DOMAIN, THEME_TEXT_DOMAIN),
            \'singular_name\' => __(\'VmGallery\', THEME_TEXT_DOMAIN),
            \'add_new\' => __(\'Add New\', THEME_TEXT_DOMAIN),
            \'add_new_item\' => __(\'Add New Gallery\', THEME_TEXT_DOMAIN),
            \'edit_item\' => __(\'Edit Gallery\', THEME_TEXT_DOMAIN),
            \'new_item\' => __(\'New Gallery\', THEME_TEXT_DOMAIN),
            \'all_items\' => __(\'All Galleries\', THEME_TEXT_DOMAIN),
            \'view_item\' => __(\'View Gallery\', THEME_TEXT_DOMAIN),
            \'search_items\' => __(\'Search Gallery\', THEME_TEXT_DOMAIN),
            \'not_found\' => __(\'No galleries found\', THEME_TEXT_DOMAIN),
            \'not_found_in_trash\' => __(\'No galleries found in the Trash\', THEME_TEXT_DOMAIN),
            \'parent_item_colon\' => \'\',
            \'menu_name\' => __(\'Gallery\', THEME_TEXT_DOMAIN),
        );
$supports = array(\'title\', \'editor\', \'thumbnail\', \'excerpt\', \'comments\', \'custom-fields\', \'post-formats\', \'author\', \'excerpt\');

 $args = array(
            \'labels\' => $labels,
            \'description\' => \'Galleries specific information\',
            \'public\' => true,
            \'menu_position\' => 6,
            \'menu_icon\' => \'dashicons-format-image\',
            \'supports\' => $supports,
            \'taxonomies\' => array(\'gallery_categories\', \'post_tag\'),
            \'has_archive\' => \'gallery\'
        );

        register_post_type(\'vmgallery\', $args);

1 个回复
SO网友:Milo

您没有显式设置slug,因此它使用您向其注册的post类型键。要将其设置为gallery,请设置slug 属于rewrite 参数:

$args = array(
    \'rewrite\' => array( \'slug\' => \'gallery\' ),
    // the rest of your args...
);
register_post_type( \'vmgallery\', $args );
See the Codex page for register_post_type for a full list of parameters.

相关推荐