Skip Navigation

[Resolved] wp_insert_post with Toolset custom taxonomy

This support ticket is created 2 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 1 reply, has 2 voices.

Last updated by Minesh 2 years, 1 month ago.

Assisted by: Minesh.

Author
Posts
#2521961
Screenshot 2022-12-25 at 4.50.15 PM.png

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);
#2522907

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/