注册后将自定义帖子类型更改为分层


9

与上一个问题非常相似:在注册自定义帖子类型后更改“重写”参数

我正在尝试使MarketPress产品分层化-我可以通过修改插件文件来做到这一点,但如果可以的话,我希望远离它们。

注册后但在完成所有内部重写工作之前,是否可以更改自定义帖子类型的参数?

更新:这是解决方案

而且通常情况下,我在发布问题几分钟后就找到了答案...

所以这是我在主题的functions.php文件中为解决我的问题所做的工作:

function modify_products() {
    if ( post_type_exists( 'product' ) ) {

        /* Give products hierarchy (for house plans) */
        global $wp_post_types, $wp_rewrite;
        $wp_post_types['product']->hierarchical = true;
        $args = $wp_post_types['product'];
        $wp_rewrite->add_rewrite_tag("%product%", '(.+?)', $args->query_var ? "{$args->query_var}=" : "post_type=product&name=");
        add_post_type_support('product','page-attributes');
    }
}
add_action( 'init', 'modify_products', 1 );

一切正常:层次结构,重写等:)


5
拉古尔卡(Ragulka),您能从标题中删除“已解决”并发布解决方案作为答案吗?24小时后,您将可以接受它。对于那些可能遇到相同/相似问题的人来说,这样做更容易。谢谢。
史蒂芬·哈里斯

@ragulka欢迎使用WordPress Stack Exchange!请注意:该网站不是通常的支持论坛格式,而是使用问答格式,以建立强大的知识库。问题和答案分别发布,并由社区进行上下投票。OP“接受”最能解决原始问题的答案。因此,正如斯蒂芬·哈里斯(Stephen Harris)所说:请发布您的解决方案作为“ 答案”,然后接受该答案。
Chip Bennett

嘿,对不起。我实际上试图回答自己的问题,但是我不能,我被告知要等8个小时或添加评论或编辑我的问题。所以我做了。好吧,我想我还要再等4个小时,然后我才能回答我的问题。
ragulka

Answers:


10

而且通常情况下,我在发布问题几分钟后就找到了答案...

所以这是我在主题的functions.php文件中为解决我的问题所做的工作:

function modify_products() {
    if ( post_type_exists( 'product' ) ) {

        /* Give products hierarchy (for house plans) */
        global $wp_post_types, $wp_rewrite;
        $wp_post_types['product']->hierarchical = true;
        $args = $wp_post_types['product'];
        $wp_rewrite->add_rewrite_tag("%product%", '(.+?)', $args->query_var ? "{$args->query_var}=" : "post_type=product&name=");
        add_post_type_support('product','page-attributes');
    }
}
add_action( 'init', 'modify_products', 1 );

一切正常:层次结构,重写等:)

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.