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.

I have a litlle problem. I have a custom taxonomy 'rodzaj' with value i.ex. obrazek. I use this code to add post:

$postArray = array(
                'post_status' => 'publish',
                'post_author'=> get_current_user_id(),
                'post_category'=>array($catId),
                'post_title' => $_POST['titlePhoto'],
                'tax_input' => array( 'rodzaj' => array( 'obrazek') ) , 
);

This code adds a post but without taxonomy. I tried also this:

wp_set_object_terms($postId, "obrazek", 'rodzaj', false);

Doesn't work too.

Working code is:

wp_set_post_terms( $postId, array( 'obrazek'), 'rodzaj' );

Why first 2 functions doesn't work?

I made mistake at the begining. This is full working code:

$catId = get_cat_ID("Obrazki");

         $postArray = array(
            'post_status' => 'publish',
            'post_author'=> get_current_user_id(),
            'post_category'=>array($catId),
            'post_title' => $_POST['titlePhoto'],
            'tags_input' => explode(',', $_POST['tagsPhoto'])
         );


         $postId = wp_insert_post($postArray);
         if($postId) 
         {
              wp_set_object_terms($postId, "obrazek", 'rodzaj', false);

          }

Still doesn't working: wp_set_post_terms($postId, "obrazek", 'rodzaj', false);

and 'tax_input' => array( 'rodzaj' => array( 'obrazek') ) in postArray()

share|improve this question
    
hmmm your code examples are incomplete, e.g. we don't see the part where you call wp_insert_post, register your taxonomy etc etc etc –  Tom J Nowell Jan 7 '13 at 10:17

1 Answer 1

Have you tried:

wp_set_object_terms( $postId, array( 'obrazek'), 'rodzaj' );

wp_set_object_terms and wp_set_post_terms take the same arguments. wp_set_post_terms even uses wp_set_object_terms internally. The main difference being that you used an array in the one that worked, and you didn't use an array in the one that didn't work.

share|improve this answer
1  
working code right now is: wp_set_object_terms($postId, "obrazek", 'rodzaj', false); I tried the same parameter with wp_set_post_terms but it doesn't work –  Chris Jan 8 '13 at 6:52
1  
Again can you provide the full code? Your function call is just 1 line, without the context provided by the surrounding code it is incredibly difficult to diagnose or debug. –  Tom J Nowell Jan 8 '13 at 9:19
    
Looking back at this, don't use wp_set_post_terms, just use wp_set_object_terms. Also notice my comment on the use of an array in my answer –  Tom J Nowell May 24 '13 at 16:11

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.