我创建了一个名为“designation”的自定义usermeta字段,并在循环中获取了所有元值,但它显示了重复值。我在循环和内部循环之前尝试过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>
答案 0 :(得分:0)