WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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'



    //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">  
            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>";

What do I miss, Thanks for the help.

share|improve this question

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

Your Answer


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.