I have used standard categories for a custom post type which is now causing me issues so I want to swap over to a custom taxonomy.
Two questions - firstly how do I programmatically set a custom taxonomy? - the equivalent to 'post_category' => array(21)
Secondly is there a way to transfer all the current categories that have been set to the custom taxonomy? They are all top level so no hierarchy to worry about.
Thanks Shane I thought as much.
How about the first bit - how do I programmatically set a custom taxonomy? - the equivalent to 'post_category' => array(21)
Thanks Shane.
How would I refer to the custom taxonomy Does it have a prefix like wpcf_ or is it just what I've called it?
For example I currently do this
$posttitle = 'Item-'.$postdate;
if (!post_exists( $posttitle,'','','loan'))
{$item_loan = array(
'post_title' => $posttitle,
'post_status' => 'publish',
'post_author' => get_current_user_id(),
'post_type' => 'loan',
'post_category' => array(21),
);
$result_loan = wp_insert_post( $item_loan );
So for the custom taxonomy "loan-category" what would I use instead of 'post_category' => array(21)?
This would be the correct way to set the terms. In the example above you seen that i've added 'term', this would be the slug of the term that you want to set.
Thanks Shane - I haven't tested this fully but it doesn't seem to be working. I've had a quick look and think perhaps I need to use wp_set_object_terms as oppose to wp_set_post_terms as this is a custom post but that could be a red herring.
May I leave the ticket open until I can try out your suggestion more completely.