我正在使用创建新类别galleries 分类法:
$wpdb->insert("wpem_terms", array(
\'name\'=>\'Custom Category\',
\'slug\'=>\'customcategory\',
\'term_group\'=>0,
));
//id of term
$id = $wpdb->insert_id;
$wpdb->insert("wpem_term_taxonomy", array(
\'term_id\'=>$id,
\'taxonomy\'=>\'galleries\',
\'description\'=>\'\',
\'parent\'=>\'\',
\'count\'=>\'\',
));
它正在工作。然后我正试图发布一篇新文章,其中包含这个新创建的类别:
wp_insert_post(array(
\'post_author\'=>1,
\'post_date\'=>date(\'Y-m-d H:i:s\'),
\'post_date_gmt\'=>date(\'Y-m-d H:i:s\'),
\'post_content\'=>\'\',
\'post_title\'=>\'\',
\'post_excerpt\'=>\'\',
\'post_status\'=>\'publish\',
\'comment_status\'=>\'closed\',
\'post_name\'=>\'\',
\'post_parent\'=>0,
\'post_type\'=>\'portfolio\', // with \'portfolio\' custom post type
\'post_category\'=>array($id),
));
这是发布帖子,没关系,但帖子的类别不是
Custom Category . 我认为这一行无效:
\'post_category\'=>array($id),
有什么想法吗?我也试过这个:
\'post_category\'=>array(get_cat_ID("Custom Category")),