WordPress Error: 'explode() expects parameter 2 to be string, array given' in wp_set_post_terms()
The error message 'explode() expects parameter 2 to be string, array given' in WordPress usually occurs when the $pcat variable is an array instead of a string. The explode() function requires a string as its second parameter to separate it into an array of substrings.
If $pcat is indeed an array, you need to loop through it and set each term individually using wp_set_post_terms(). Here's an example:
foreach ($pcat as $term_id) { 
    wp_set_post_terms($target_id, intval($term_id), 'qqcpat', true); 
} 
In this example, $term_id is cast to an integer using intval() before setting the post term. The fourth parameter of wp_set_post_terms() is set to true to append the terms to the existing ones, instead of replacing them.
原文地址: https://www.cveoy.top/t/topic/qiBj 著作权归作者所有。请勿转载和采集!