1

我尝试USER ID从注册期间创建的 userMeta 键获取 wordpress。

用户元键是带有元值的“lh_scuritycode” $_GET["key"]

$_GET["key"] = f16dea7e995b14e420ddb96fb7dbd67f

这是我的代码:

<?php

if ((ctype_alnum($_GET["key"])) && (strlen($_GET["key"]) == 32)) {

    $lh_users = get_users( array(
                    "meta_key" => "lh_scuritycode",
                    "meta_value" => $_GET["key"],
                    "number" => 1,
                    "count_total" => false
                ) );

    foreach ($lh_users as $lh_user) {
        echo '<li>' . $lh_user->id . '</li>';
    }

} else {    
    echo "Der String ".$_GET["key"]." ist fehlerhaft.\n";   
}

?>

现在,$lh_users如果我echo它只是一个数组。当我使用foreach它时,它可以工作。没有那个我怎么办foreach

当我这样做“var_dump”时,结果是:

array(1) { [0]=> object(WP_User)#126 (7) { ["data"]=> object(stdClass)#2077 (10) { ["ID"]=> string(2) "24 " ["user_login"]=> 字符串(7) "Aner" ["user_pass"]=> 字符串(34) "$P$BDpMKv0" ["user_nicename"]=> 字符串(7) "aner" ["user_email" ]=> string(18) "infe" ["user_url"]=> string(0) "" ["user_registered"]=> string(19) "2013-0 1:02" ["user_activation_key"]=> string (0) "" ["user_status"]=> 字符串(1) "0" ["display_name"]=> 字符串(7) "Aner" } ["ID"]=> int(24) ["caps"] => 数组(1) { ["订阅者"]=> bool(true) } ["cap_key"]=> 字符串(22) "localhero_capabilities" ["roles"]=> array(1) { [0]=> string(10) "subscriber" } ["allcaps"]=> array(3) { ["read"]=> bool(true) ["level_0"]=> bool(true) ["subscriber"]=> bool(true) } ["filter"]=> NULL } }

And How do I echo this ARRAY1[id]?

Thanks to GWC

I do it this way:

if ((ctype_alnum($_GET["key"])) && (strlen($_GET["key"]) == 32)) {

$lh_users = get_users( array(
"meta_key" => "lh_scuritycode",
"meta_value" => $_GET["key"],
"number" => 1, "fields" => "ID"
) );

$this_user = $lh_users[0];

echo $this_user;
4

1 回答 1

4

If all you want is a list of user IDs:

$lh_users = get_users( array(
                "meta_key" => "lh_scuritycode",
                "meta_value" => $_GET["key"],
                "fields" => "ID"
            ) );

echo '<li>' . implode( '</li><li>', $lh_users ) . '</li>';
于 2013-09-09T19:16:48.570 回答