wordpress unset user_meta数组值

时间:2013-10-31 22:18:04

标签: php wordpress

我尝试了常规的php未设置,但没有成功。一切看起来都在这里,但它仍然在数组中

$profileID = $_POST['profileID'];
$userID = $_POST['userID'];

    $reChkMetaValue = get_user_meta($userID,'friends',true);
    foreach($reChkMetaValue as $key => $value) {

if( ( $key = array_search($profileID, $reChkMetaValue) ) !== false );
    unset( $reChkMetaValue[$key] );
    }

1 个答案:

答案 0 :(得分:0)

尝试对用户元素进行操作。如果数据的值匹配,请记录密钥。然后从阵列中取消它。

<?php
    $user_meta = get_user_meta($userID,'favs',true);
    $key_found = false;
    foreach($user_meta as $key => $value)
    {
        if(!$key_found){
             if($value == 'THE THING YOU WANT TO FIND'){
                 $remove_key = $key;
                 $key_found = true;
             }
        }
    }
    unset($user_meta[$remove_key]);
?>