我在wordpress中插入了产品价格,名称和大小的值。插入代码在
下面function products_save_postdata($post_id) {
if (isset ($_POST['price'])) {
update_post_meta($post_id, 'price', esc_attr($_POST['price']));
}
if (isset ($_POST['product_name'])) {
update_post_meta($post_id, 'product_name', esc_attr($_POST['product_name']));
}
if (isset ($_POST['size'])) {
update_post_meta($post_id, 'size', esc_attr($_POST['size']));
}
}
如何获取此插入的数据?
答案 0 :(得分:0)
您可以使用此功能代替您的功能:
function products_save_postdata($post_id)
{
$array = array();
if (isset ($_POST['price'])) {
update_post_meta($post_id, 'price', esc_attr($_POST['price']));
$array['price'] = $_POST['price'];
}
if (isset ($_POST['product_name'])) {
update_post_meta($post_id, 'product_name', esc_attr($_POST['product_name']));
$array['product_name'] = $_POST['product_name'];
}
if (isset ($_POST['size'])) {
update_post_meta($post_id, 'size', esc_attr($_POST['size']));
$array['size'] = $_POST['size'];
}
return $array;
}
获取值:
$post_data = products_save_postdata($post_id);
echo $post_data['price'];
echo $post_data['product_name'];
echo $post_data['size'];