嗨,我的好朋友们,比起失去理智,我更需要你们的帮助,首先我要感谢“斯蒂芬·哈里斯”good article ,
-第二:在进行了大量搜索之后,我仍然不知道如何将自定义分类法注入到自定义帖子类型中。下面是我的代码:
$post_id = wp_insert_post(array(
\'post_author\' => $user_id,
\'post_title\' => $post_title,
\'post_content\' => $post_content,
\'post_category\' => array($_POST[\'cat\']), // Usable for custom taxonomies too
\'tax_input\' => array(\'offer\' => $terms),
\'tags_input\' => array($tags),
\'post_type\' => \'classified\',
\'post_status\' => \'publish\'
));
update_post_meta($post_id,\'$term->term_id\',$taxonomy,true);
以及
<?php
//Set up the taxonomy object and get terms
$taxonomy = \'offer\';
$tax = get_taxonomy($taxonomy); //This is the taxonomy object
$name = \'tax_input[\' . $taxonomy . \']\';
$terms = get_terms($taxonomy, array(\'hide_empty\' => 0));
$postterms = get_the_terms($post->ID, $taxonomy);
$current = ($postterms ? array_pop($postterms) : false);
$current = ($current ? $current->term_id : 0);
?>
<!-- Display taxonomy terms -->
<div id="<?php echo $taxonomy; ?>-all" class="tabs-panel">
<ul id="<?php echo $taxonomy; ?>checklist" class="list:<?php echo $taxonomy ?> categorychecklist form-no-clear">
<?php
foreach ($terms as $term) {
$id = $taxonomy . \'-\' . $term->term_id;
echo "<li id=\'$id\'><label class=\'selectit\'>";
echo "<input type=\'radio\' id=\'in-$id\' name=\'{$name}\'" . checked($current, $term->term_id, false) . "value=\'$term->term_id\' />$term->name<br />";
echo "</label></li>";
}
?>
</ul>
</div>
我错过了什么,谢谢你的帮助。