Я вижу во многих местах, что WordPress автоматически сериализует массивы с помощью update_post_meta.
Но в их документах указано, что вам следует сериализовать его перед использованием update_post_meta. https://developer.wordpress.org/referen ... post_meta/
Я также получаю разные результаты при использовании get_post_meta, который использует сериализованное значение или массив. $val = array();
$val['one'] = 1;
$val['two'] = 2;
$val['threed']['x'] = 'ex';
$val['threed']['y'] = 'why';
$ser = serialize($val);
update_post_meta($order_id, 'testing arr', $val);
update_post_meta($order_id, 'testing ser arr', $ser);
// This was saved in the table as...
// a:3:{s:3:"one";i:1;s:3:"two";i:2;s:6:"threed";a:2:{s:1:"x";s:2:"ex";s:1:"y";s:3:"why";}}
// s:88:"a:3:{s:3:"one";i:1;s:3:"two";i:2;s:6:"threed";a:2:{s:1:"x";s:2:"ex";s:1:"y";s:3:"why";}}";
$testarr = get_post_meta($order_id, 'testing arr');
$testarrser = get_post_meta($order_id, 'testing ser arr');
Using get_post_meta for each of the above and printing the array gives the following:
NOTE 1: get_post_meta($id, $field, true) and get_post_meta($id, $field, false) return the same data structure.
NOTE 2: These were not unserialized - just print_r() the returned values.
testarr: Array(
[0] => Array (
[one] => 1
[two] => 2
[threed] => Array (
[x] => ex
[y] => why
)
)
)
testarrser: Array(
[0] => a:3:{s:3:"one";i:1;s:3:"two";i:2;s:6:"threed";a:2:{s:1:"x";s:2:"ex";s:1:"y";s:3:"why";}}
)
Please explain the correct way to update_post_meta to retrieve the expected array.
Подробнее здесь: https://stackoverflow.com/questions/787 ... rce-orders
Использование метафункций публикации WordPress с переменными массива в заказах WooCommerce ⇐ Php
Кемеровские программисты php общаются здесь
1720127839
Anonymous
Я вижу во многих местах, что WordPress автоматически сериализует массивы с помощью update_post_meta.
Но в их документах указано, что вам следует сериализовать его перед использованием update_post_meta. https://developer.wordpress.org/reference/functions/update_post_meta/
Я также получаю разные результаты при использовании get_post_meta, который использует сериализованное значение или массив. $val = array();
$val['one'] = 1;
$val['two'] = 2;
$val['threed']['x'] = 'ex';
$val['threed']['y'] = 'why';
$ser = serialize($val);
update_post_meta($order_id, 'testing arr', $val);
update_post_meta($order_id, 'testing ser arr', $ser);
// This was saved in the table as...
// a:3:{s:3:"one";i:1;s:3:"two";i:2;s:6:"threed";a:2:{s:1:"x";s:2:"ex";s:1:"y";s:3:"why";}}
// s:88:"a:3:{s:3:"one";i:1;s:3:"two";i:2;s:6:"threed";a:2:{s:1:"x";s:2:"ex";s:1:"y";s:3:"why";}}";
$testarr = get_post_meta($order_id, 'testing arr');
$testarrser = get_post_meta($order_id, 'testing ser arr');
Using get_post_meta for each of the above and printing the array gives the following:
NOTE 1: get_post_meta($id, $field, true) and get_post_meta($id, $field, false) return the same data structure.
NOTE 2: These were not unserialized - just print_r() the returned values.
testarr: Array(
[0] => Array (
[one] => 1
[two] => 2
[threed] => Array (
[x] => ex
[y] => why
)
)
)
testarrser: Array(
[0] => a:3:{s:3:"one";i:1;s:3:"two";i:2;s:6:"threed";a:2:{s:1:"x";s:2:"ex";s:1:"y";s:3:"why";}}
)
Please explain the correct way to update_post_meta to retrieve the expected array.
Подробнее здесь: [url]https://stackoverflow.com/questions/78703062/using-wordpress-post-meta-functions-with-array-variables-on-woocommerce-orders[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия