I have a function that runs with user input variable (comma separated numeric string) to update the terms (by id) in a custom taxonomy on a custom post type. Even though the docs say I should use wp_set_object_terms, I can only get my terms to update by using wp_set_post_terms. The following code will work (using wp_set_post_terms but not using wp_set_object_terms at the end):

if(isset($request['custom_tax'])) {
$customtaxarray = explode(",",$request['custom_tax']);
$only_integers = true;
foreach ($customtaxarray as $testcase) {
    if (!ctype_digit($testcase)) {
    $only_integers = false;
if ($only_integers) {
$customtax = $customtaxarray;
} else {

return array(
                'code' => 'missing_integers',
                'data' => array(
                    'status' => 403,
                    'message' => "custom_tax must be one or more (comma separated) integers.",
//update custom_tax
wp_set_post_terms($request['cpt_post_id'], $customtax, 'custom_tax' );


Read more here: wp_set_object_terms NOT working on CPT, but wp_set_post_terms does


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: