我创建了一个名为“designation”的自定义用户元字段,并在循环中获取其所有元值,但它显示了 duplicates 值。我在循环之前和循环内部尝试过 array_unique() 函数,但不起作用。请指导我如何删除重复项。
<form action="" method="post">
<select name="designation" onchange="if(this.value != 0) && if(this.value != 1){ this.form.submit(); }">
<option value="1">Select Category</option>
<?php
$args = array(
'role' => 'subscriber',
'meta_key' => 'user_designation'
);
$design = array_unique($args);
var_dump($design);
// The Query
$user_query = new WP_User_Query($design);
// User Loop
if ( !empty($user_query->results) ) {
foreach ( $user_query->results as $user ) {
?>
<option value="<?php echo get_user_meta($user->ID, 'user_designation', true); ?>"
<?php if (isset($_POST['designation']) && $_POST['designation'] == "echo get_user_meta($user->ID, 'user_designation', true);") {echo "selected";} ?> >
<?php echo get_user_meta($user->ID, 'user_designation', true); ?>
</option>
<?php
}
} else {
?>
<option value="0">No Category Found</option>
<?php
}
?>
</select>
</form>