有没有办法从序列化元值中搜索?在wp_query中有meta_query选项。假设我必须查看是否有product_id=74
。我的整个元值是:
a:1:{i:0;a:3:{s:15:"menu_group_name";s:4:"Fish";s:22:"menu_group_cover_photo";a:1:{i:0;s:2:"70";}s:22:"menu_group_single_menu";a:2:{i:0;a:4:{s:16:"single_menu_name";s:19:"Chicken Chilli Fist";s:16:"single_menu_desc";s:74:"lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriur";s:6:"_price";s:4:"9.99";s:10:"product_id";s:2:"73";}i:1;a:4:{s:16:"single_menu_name";s:17:"Fist Onion Breast";s:16:"single_menu_desc";s:67:"lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eu";s:6:"_price";s:4:"2.99";s:10:"product_id";s:2:"74";}}}}
答案 0 :(得分:0)
有两种功能非常适合您的需求:maybe_unserialize()
和maybe_serialize()
。在您的情况下,您需要使用仅在序列化时才会反序列化值的maybe_unserialize()
。
您可以从codex maybe_serialize()
中了解更多信息