感谢@BAInternet的解决方案。问题似乎是,因为我正在创建一篇帖子,save函数被调用了两次,因此帖子的数量呈指数级增长。我想到的解决方案是:
public function save() {
global $post;
global $flag;
//Following code makes sure it doesn\'t get executed twice
if($flag ==0) $flag =1;
else return;
//Next to temporarily disable this filter
remove_action(\'save_post\', array(&$this, __FUNCTION__));
$my_child = array(
\'post_title\' => $this->_child_type,
\'post_content\' => "test content",
\'post_status\' => \'publish\',
\'post_type\' => "video",
\'post_parent\'=> 55
);
$nindex = wp_insert_post($my_child);
}
//restore save
add_action(\'save_post\', array(&$this, __FUNCTION__));
}
add_action(\'save_post\', array(&$this, \'save\'));