2012-07-02 66 views
1

下面是代码:为什么我不能在类对象中添加register_post_type或taxonomy?

<?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); 
     } 
    } 


} 
?> 

它不注册类型后因某种原因?但是当我在index.php中放入相同的register_post_type函数时,它工作正常

+0

这是我确切的问题(回答工作)。为什么我每天都继续使用SO。 – orolo

回答

2

您可能试图在初始化之前运行寄存器。只要将你的类的这个方法挂钩到init钩子(或者在它之后运行的任何东西,比如theme_setup),你就可以很好地去。

相关问题