如果我使用以下硬代码,请从自定义子菜单页:
$post_id = 111;
$flightCategory = array( 25 );
wp_set_object_terms( $post_id, $flightCategory, \'flight_categories\' );
并刷新页面,它只需将所需的自定义分类术语分配给CPT。但是如果我继续下面的代码,我将从<form>
, 它不像以前那样工作。if( $flightID !== NULL && $flightCat !== \'-1\' && !empty( $flightCat ) ) {
$flightCount = count( $flightID );
foreach ( $flightID as $post_id ) {
$flightCategory = array( $flightCat ); //inactive = 25, active = 26
wp_set_object_terms( $post_id, $flightCategory, \'flight_categories\' );
}
$success = sprintf( __(\'<strong>SUCCESS:</strong> %d Flight information has been affected\', \'textdomain\'), $flightCount);
} else {
$error = __(\'<strong>ERROR:</strong> You can\\\'t pass any empty field\', \'textdomain\');
}
这个代码块的作用是,它简单地添加了名为“25”的新术语和slug“25”。我尝试不传递如下数组:$flightCategory = $flightCat;
但结果是一样的。我做错了什么?