如何从 wordpress 中的这个对象数组中检索我的值

时间:2021-05-26 20:53:20

标签: sql arrays json wordpress object

我通过functions.php在dokan的供应商设置页面上添加了一个额外的字段。 遵循此文档:https://wedevs.com/108107/how-to-add-extra-field-on-vendor-settings-page/

由于该值已保存在 wp_usermeta 表中,因此尝试通过查询获取数据:

global $wpdb;
$result = $wpdb->get_results("Select `meta_value` from `wp_usermeta` where `meta_key` = 'dokan_profile_settings'");
print_r($result);

这个打印语句给了我以下对象数组:

    Array
(
    [0] => stdClass Object
        (
        )

    [1] => stdClass Object
        (
        )

    [2] => stdClass Object
        (
        )

    [3] => stdClass Object
        (
            [meta_value] => a:30:{s:10:"store_name";s:11:"Dokan Store";s:6:"social";a:0:{}s:7:"payment";a:2:{s:6:"paypal";a:1:{i:0;s:5:"email";}s:4:"bank";a:0:{}}s:5:"phone";s:10:"1234567890";s:10:"show_email";s:2:"no";s:7:"address";a:6:{s:8:"street_1";s:0:"";s:8:"street_2";s:0:"";s:4:"city";s:0:"";s:3:"zip";s:0:"";s:7:"country";s:2:"IN";s:5:"state";s:2:"DL";}s:8:"location";s:1:",";s:6:"banner";i:0;s:4:"icon";i:0;s:8:"gravatar";i:0;s:14:"show_more_ptab";s:3:"yes";s:9:"store_ppp";i:10;s:10:"enable_tnc";s:3:"off";s:9:"store_tnc";s:0:"";s:23:"show_min_order_discount";s:0:"";s:9:"store_seo";a:0:{}s:24:"dokan_store_time_enabled";s:2:"no";s:23:"dokan_store_open_notice";s:0:"";s:24:"dokan_store_close_notice";s:0:"";s:12:"find_address";s:0:"";s:16:"dokan_store_time";a:7:{s:6:"sunday";a:3:{s:6:"status";s:5:"close";s:12:"opening_time";s:0:"";s:12:"closing_time";s:0:"";}s:6:"monday";a:3:{s:6:"status";s:5:"close";s:12:"opening_time";s:0:"";s:12:"closing_time";s:0:"";}s:7:"tuesday";a:3:{s:6:"status";s:5:"close";s:12:"opening_time";s:0:"";s:12:"closing_time";s:0:"";}s:9:"wednesday";a:3:{s:6:"status";s:5:"close";s:12:"opening_time";s:0:"";s:12:"closing_time";s:0:"";}s:8:"thursday";a:3:{s:6:"status";s:5:"close";s:12:"opening_time";s:0:"";s:12:"closing_time";s:0:"";}s:6:"friday";a:3:{s:6:"status";s:5:"close";s:12:"opening_time";s:0:"";s:12:"closing_time";s:0:"";}s:8:"saturday";a:3:{s:6:"status";s:5:"close";s:12:"opening_time";s:0:"";s:12:"closing_time";s:0:"";}}s:18:"profile_completion";a:7:{s:5:"phone";i:10;s:10:"store_name";i:10;s:8:"location";N;s:4:"Bank";i:30;s:9:"next_todo";s:10:"banner_val";s:8:"progress";i:50;s:13:"progress_vals";a:7:{s:10:"banner_val";i:15;s:19:"profile_picture_val";i:15;s:14:"store_name_val";i:10;s:11:"address_val";i:10;s:9:"phone_val";i:10;s:18:"payment_method_val";i:30;s:10:"social_val";a:4:{s:2:"fb";i:4;s:7:"twitter";i:2;s:7:"youtube";i:2;s:8:"linkedin";i:2;}}}s:28:"setting_minimum_order_amount";s:0:"";s:24:"setting_order_percentage";s:0:"";s:16:"vendor_biography";s:0:"";s:10:"seller_url";s:29:"https://vishakha.me1234567890";s:12:"billing_city";s:7:"1234567";s:16:"billing_postcode";s:6:"Estado";s:13:"billing_state";s:3:"CEP";s:17:"billing_address_1";s:0:"";}
        )

)

我需要获取第三个对象中的 seller_url 的值。有没有办法获得价值?请帮忙。

1 个答案:

答案 0 :(得分:0)

经过研究和试验,我得到了问题的解决方案。也贴出答案:

foreach ( $result as $userdata ) {
        $temp = $userdata->meta_value;
        $data = unserialize($temp);
        $temp2 = $data['seller_url'];
}

print_r($temp2); // will return the seller_url