1

这是代码:

<?php  

// (wp_plugin_dir/My_plugin/index.php) 
class interface{
    __construct(){
    $this->get_commerce();
    }

}

$interface = new interface();

// (wp_plugin_dir/My_plugin/commerce/commerce.php) 

    class commerce{
        __construct(){
            $this->register_post_types();
        }

        function register_post_types(){
            $args = array( 'public' => true, 'label' => 'Books' );
            register_post_type( 'book', $args );
        }
    }


}
?>

由于某种原因它没有注册帖子类型?但是当我将相同的 register_post_type 函数放入 index.php 时,它工作正常

4

1 回答 1

2

您可能正在尝试在初始化之前运行寄存器。只需将您的类的该方法挂钩到 init 挂钩(或在它之后运行的任何东西,例如 theme_setup),您就可以开始了。

于 2012-08-23T23:53:04.267 回答