Skip Navigation

[Resolved] wp_insert_post with Toolset custom taxonomy

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.

Our next available supporter will start replying to tickets in about 0.87 hours from now. Thank you for your understanding.

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 1 year, 11 months 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/