Unable to add category to custom post

Hello,

I’m using wp_insert_post() to insert a custom post. This works fine, except I cannot assign any categories to it.

The custom post type is “property” and has a custom taxonomy called “property_type”. The taxonomy is registered, and works fine in the WordPress admin.

register_taxonomy(‘property_type’, ‘property’, array(‘hierarchical’ => true, ‘label’ => ‘Property Type’, ‘query_var’ => true, ‘rewrite’ => true));

One category is called ‘apartment’ with ID 7.

I’ve tried the following:

– Filling the “tags_input” argument of wp_insert_post() with “apartment”.

– Filling the “tax_input” argument of wp_insert_post() with array(“property_type” => array(7))

– Filling the “tax_input” argument of wp_insert_post() with array(“property_type” => array(‘apartment’:wink:)

– wp_set_post_terms($post_id, ‘apartment’, ‘property_type’:wink:;

– wp_set_post_terms($post_id, 7, ‘property_type’:wink:;

– wp_set_post_terms($post_id, ‘apartment’, ‘category’:wink:;

– wp_set_post_terms($post_id, 7, ‘category’:wink:;

– wp_set_post_terms($post_id, ‘apartment’, ‘post_tag’:wink:;

– wp_set_post_terms($post_id, 7, ‘post_tag’:wink:;

Absolutely none of those pieces of code manages to set the category of my custom post. The post is being inserted just fine, i can add meta options, just not the category.

Any help would be greatly appreciated.