Dear Sir/Madam,
I created the Toolset custom taxonomy, how can I assign the category to post when using wp_insert_post()? Below is my code but doesn't work.
$args = [
"post_type" => "log",
"post_title" => "Update member info",
"post_content" => $post_content,
"post_status" => "publish",
"post_categories" => "update",
"meta_input" => [
"wpcf-log-author-id" => get_current_user_id(),
"wpcf-log-timestamp" => strtotime("+8 hour"),
"wpcf-log-member-id" => get_the_ID()
]
];
$id = wp_insert_post($args);
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Hello. Thank you for contacting the Toolset support.
Actually, this is certainly does not related to Toolset and its pure custom code but as this is a small thing I'm happy to guide you in the right direction.
Can you please try to use the following code:
$args = [
"post_type" => "log",
"post_title" => "Update member info",
"post_content" => $post_content,
"post_status" => "publish",
"tax_input" => array('log-category'=>array("update")),
"meta_input" => [
"wpcf-log-author-id" => get_current_user_id(),
"wpcf-log-timestamp" => strtotime("+8 hour"),
"wpcf-log-member-id" => get_the_ID()
]
];
$id = wp_insert_post($args);
More info:
- https://developer.wordpress.org/reference/functions/wp_insert_post/