具有自定义帖子类型的前端无线电自定义分类

时间:2012-04-15 作者:Ehab Fawzy

嗨,我的好朋友们,比起失去理智,我更需要你们的帮助,首先我要感谢“斯蒂芬·哈里斯”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>  
我错过了什么,谢谢你的帮助。

1 个回复
SO网友:Bainternet

您的代码不会显示是否以及如何设置$terms 除此之外,它看起来还可以,只需尝试将其包装在一个数组中,您应该首先检查它是否已设置,所以请尝试以下操作:

$new_post = array(
    \'post_author\' => $user_id,
    \'post_title\' => $post_title,
    \'post_content\' => $post_content,
    \'post_category\' =>   array($_POST[\'cat\']),
    \'tags_input\' => array($tags),
    \'post_type\' => \'classified\',
    \'post_status\' => \'publish\'
));
if (isset($_POST[\'tax_input\'][\'offer\'])
$new_post[\'tax_input\'] array(\'offer\' => (array)$_POST[\'tax_input\'][\'offer\']);
$post_id = wp_insert_post($new_post);

结束

相关推荐

Front-End Post Submission

我正在尝试添加一个表单,用户可以从前端提交帖子。我正在学习本教程:http://wpshout。com/wordpress从前端提交帖子/我正在做的是添加this code 到我的一个页面模板。表单显示正常,但当我单击“提交”按钮时,它会显示“Page not found error“”许多评论者说这不起作用。谁能给我指出正确的方向吗?代码是否不完整?有缺陷吗?我做错什么了吗?谢谢Towfiq I。