使用从数据库中提取信息的最佳方法是什么get_post_meta
?
field name = invoice_details
value = a:20:{s:15:"price_per_night";s:3:"150";s:12:"no_of_nights";s:1:"1";s:23:"price_calulating_nights";s:3:"150";s:22:"price_after_commission";s:3:"150";s:13:"discount_type";s:0:"";s:20:"price_after_discount";s:3:"150";s:16:"discounted_price";s:1:"0";s:19:"discount_percentage";s:0:"";s:17:"total_service_fee";s:2:"60";s:11:"total_price";s:3:"210";s:8:"currency";s:3:"GBP";s:7:"post_id";s:2:"21";s:8:"check_in";s:10:"02-07-2017";s:9:"check_out";s:10:"03-07-2017";s:6:"guests";s:1:"1";s:16:"security_deposit";s:3:"100";s:10:"secret_key";s:30:"FfmtXmaPOKbrS8B1XLugufiD3Hdjxl";s:10:"updated_at";s:19:"2017-06-25 17:04:33";s:18:"booking_request_by";i:2;s:17:"step_2_attributes";a:9:{s:9:"firstname";s:3:"Tom";s:8:"lastname";s:5:"Smith";s:14:"street_address";s:3:"229";s:11:"postal_code";s:8:"YW11 3DU";s:4:"city";s:6:"London";s:7:"country";s:14:"United Kingdom";s:5:"phone";s:10:"0799999999";s:11:"guest_fname";a:1:{i:1;s:5:"Bella";}s:11:"guest_lname";a:1:{i:1;s:4:"King";}}}
例如,如何将“firstname”字段检索为“James”?我目前正在使用:
$billing_firstname = get_post_meta( $post->ID, $invoice_details[\'firstname\'] , true );
非常感谢。
未序列化值:
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\',
),
),
)