1

Since I use cron jobs for automation I ran into some problems with the taxonomy. Before I used the cron job, the following code used to work:

$custom_tax = array(
    "project-type" => array(
        "2"
    )
);
$mypost = array(
    'post_title' => $basicdata["Model"],
    'post_type' => "portfolio",
    'post_status' => "publish",
    'tax_input' => $custom_tax,
    'comment_status' => "closed"
);
$pid = wp_insert_post($mypost);

I know when I use cron jobs, can't use tax_input in wp_insert_post() anymore, but it should work with wp_set_post_terms(). I didn't really understand how to achieve the same thing with wp_set_post_terms() by reading the WordPress codex. Would be nice if anyone could help me...

2

After some hours of further searching i found the solution:

wp_set_post_terms($pid, array("2"), "project-type");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.