我尝试了在线反序列化工具,但未能解释您的价值,因为它已损坏。
无论如何,获取值的方法如下所示:
// Get the value from db first
$meta_value = get_post_meta( $post->ID, \'invoice_details\' , true ); //\'invoice_details\' is a string, not a variable
// Get to the desired value
$desired_value = $meta_value[\'array_key\']; // value from first step of array
或:
$desired_value = $meta_value[\'array_key\'][\'array_key_second\']; // value from second step of array
你应该
var_dump($meta_value)
在拥有
$meta_value
了解如何处理数据。
编辑我只是按如下方式组织了您的阵列:
<?php
array (
\'price_per_night\' => \'150\',
\'no_of_nights\' => \'1\',
\'price_calulating_nights\' => \'150\',
\'price_after_commission\' => \'150\',
\'discount_type\' => \'\',
\'price_after_discount\' => \'150\',
\'discounted_price\' => \'0\',
\'discount_percentage\' => \'\',
\'total_service_fee\' => \'60\',
\'total_price\' => \'210\',
\'currency\' => \'GBP\',
\'post_id\' => \'21\',
\'check_in\' => \'02-07-2017\',
\'check_out\' => \'03-07-2017\',
\'guests\' => \'1\',
\'security_deposit\' => \'100\',
\'secret_key\' => \'FfmtXmaPOKbrS8B1XLugufiD3Hdjxl\',
\'updated_at\' => \'2017-06-25 17:04:33\',
\'booking_request_by\' => 2,
\'step_2_attributes\' => array (
\'firstname\' => \'Tom\',
\'lastname\' => \'Smith\',
\'street_address\' => \'229\',
\'postal_code\' => \'YW11 3DU\',
\'city\' => \'London\',
\'country\' => \'United Kingdom\',
\'phone\' => \'0799999999\',
\'guest_fname\' => array (
1 => \'Bella\',
),
\'guest_lname\' => array (
1 => \'King\',
),
),
);
它本身给了你答案。是的,只需访问嵌套键:
$firstname = $meta_value[\'step_2_attributes\'][\'firstname\'];
如果
\'firstname\'
设置后,您将获得名字。
客人名字:
$guestFirstname = $meta_value[\'step_2_attributes\'][\'guest_fname\'][1];