Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Hi my good friends I need your help better than losing my mind, first I have to thank "Stephen Harris" for his good article ,

-second: After a lot of searching I still don't know how to inject a custom taxonomy to a custom post type Here is my code:

  $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);

and

   <?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>  

What do I miss, Thanks for the help.

share|improve this question
add comment

1 Answer

Your code doesn't show if and how you set $terms other then that its seems ok, just try to wrap it in an array and you should check if its set first, so try this:

$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);
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.