我正在使用Post 2 Post插件创建帖子类型之间的关系,并且我试图连接Sub -type category post type to a category post type in the following function,but I have this error message:致命错误:调用布尔型的成员函数connect()。P2P-> connect():致命错误:调用布尔型的成员函数connect()
当我回显$ p2p值时,它显示“false”,但为什么?
任何人都可以帮助我吗?谢谢!
导入功能:
function import_subCategories(){
global $co;
$query = "SELECT * FROM `tl_events_sous_categories`";
$result = $co->query($query);
while($data = mysqli_fetch_array($result)){
$my_post = array(
'post_title' => iconv('ISO-8859-1','UTF-8', $data['headline']),
'post_content' => '',
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'sub-categorie'
);
$the_post_id = wp_insert_post($my_post);
// Create the relationship between CATEGORY and SUB CATEGORY
$p2p = p2p_type('sous_categories_categorie');
$p2p->connect($the_post_id, $data['pid'], array('date' => current_time('mysql')));
if(is_wp_error($p2p)){
echo $p2p->get_error_message();
}
}
}`
连接类型:(中的functions.php)
function my_connection_types() {
p2p_register_connection_type(array(
'name' => 'sous_categories_categorie',
'from' => 'sub-categorie',
'to' => 'categorie'
));
}
编辑:看来我的连接类型被注册,因为它出现在WP工具菜单: WP Tools menu
谢谢你的回答!传递给p2p_type()的$ id参数是p2p_register_connection_type()中使用的'name'值吗?因为这是我做的,但不起作用 – Gillian
@Gillian从我可以从源代码中得知,是的。查看我的更新。 – Gordon
感谢您的指示。看起来P2P_Connection_Type不存在(不再?),所以我改用P2P_Connection_Type_Factory。我有一个空的数组...所以,我的连接类型没有注册,但我不知道为什么..我不知道我的代码有什么问题... – Gillian