从自定义POST类型中删除自定义固定链接结构,而不直接修改REGISTER_POST_TYPE

时间:2015-07-01 作者:Josh Warren

我正在为我的帖子使用自定义的永久链接结构,/blog/%postname%/. 我安装了一个插件,可以注册自定义的帖子类型,glossary. 我不希望此帖子类型使用标准帖子使用的自定义permalinks结构。我相信这个环境\'rewrite\' => array(\'with_front\' => false) 注册post类型时,将完成此操作。问题是帖子类型是由插件注册的,所以我不能直接在插件的代码中修改函数,至少如果我想要一个防升级的补丁的话。如何通过主题函数向数组中添加参数。php文件,而不是插件的代码?

以下是插件用于注册帖子类型的函数,以防有所帮助:

public function register_post_types(){
    register_post_type( \'glossary\', array(
        \'public\'               => true,
        \'menu_position\'        => 105,
        \'has_archive\'          => true,
        \'supports\'             => array( \'title\', \'editor\', \'thumbnail\', \'author\', \'excerpt\' ),
        \'labels\' => array(
            \'name\'               => __( \'Glossary Terms\',                   \'wp-glossary\' ),
            \'singular_name\'      => __( \'Glossary Term\',                    \'wp-glossary\' ),
            \'add_new\'            => __( \'Add New Term\',                     \'wp-glossary\' ),
            \'add_new_item\'       => __( \'Add New Glossary Term\',            \'wp-glossary\' ),
            \'edit_item\'          => __( \'Edit Glossary Term\',               \'wp-glossary\' ),
            \'new_item\'           => __( \'Add New Glossary Term\',            \'wp-glossary\' ),
            \'view_item\'          => __( \'View Glossary Term\',               \'wp-glossary\' ),
            \'search_items\'       => __( \'Search Glossary Terms\',            \'wp-glossary\' ),
            \'not_found\'          => __( \'No Glossary Terms found\',          \'wp-glossary\' ),
            \'not_found_in_trash\' => __( \'No Glossary Terms found in trash\', \'wp-glossary\' )
        ),
        \'register_meta_box_cb\' => array( $this, \'meta_boxes\' ),
        \'rewrite\'              => array( \'slug\' => sanitize_title( _x( \'glossary\', \'rewrite slug\', \'wp-glossary\' ) ) ),
    ) );

    add_filter( \'manage_glossary_posts_columns\',       array($this, \'manage_glossary_posts_columns\') );
    add_action( \'manage_glossary_posts_custom_column\', array($this, \'manage_glossary_posts_custom_column\'), 10, 2 );

    add_action( \'save_post\',   array(&$this, \'save_glossary_post\'), 10, 2 );
    add_filter( \'the_content\', array(&$this, \'the_content\'),        10, 2 );
} 

1 个回复
最合适的回答,由SO网友:mmm 整理而成

您可以这样做来修改定义

$args = get_post_type_object("glossary");
$args->rewrite = array("with_front" => FALSE);
register_post_type($args->name, $args);
这必须在调用插件的“register\\u post\\u types()”后完成

结束

相关推荐

Dynamic Custom Permalinks

我有一个场景,其目的是创建可以动态更改的自定义永久链接,例如:如果显示国家信息,则URL应为http://example.com/country-information如果显示特定国家的城市信息,则URL应如下所示http://example.com/country/city-information. 我怎样才能做到这一点?