Wordpress 元值(序列化)过滤器
Wordpress Meta Value (Serialized) Filter
我有一个元键 _student_registration_data
存储在 wordpress 数据库中,具有元值作为序列化数组,如下所示:
a:9:{s:4:"name";s:20:"John Doe";s:11:"father_name";s:10:"Arnold";s:4:"cnic";s:13:"5540545612812";s:12:"home_address";s:9:"Scheme-33";s:16:"telephone_number";s:12:"923332654324";s:15:"registration_id";s:6:"08CS68";s:10:"program_id";s:1:"1";s:9:"cohort_id";s:1:"6";s:10:"section_id";s:1:"7";}
现在我想要一个 mysql 查询或一些内置的 wordpress 函数,借助它我可以过滤具有 registration_id
等于 08CS68
.
的 usermeta 行
谢谢。
您可以使用 SUBSTRING_INDEX
:
从您的字符串中提取 registration_id
SELECT *
FROM yourtable
WHERE SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(_student_registration_data,
'registration_id', -1), ';', 2), ':', -1) = '"08CS68"'
尼克的回答是关键,但没有解决我的问题。这是实际起作用的:
SELECT * FROM (SELECT * FROM `cn_usermeta` WHERE meta_key = '_student_registration_data') as META WHERE SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(META.meta_value, 'registration_id', -1), ';', 2), ':', -1) = '"08CS68"'
特别感谢 Nick :)
我有一个元键 _student_registration_data
存储在 wordpress 数据库中,具有元值作为序列化数组,如下所示:
a:9:{s:4:"name";s:20:"John Doe";s:11:"father_name";s:10:"Arnold";s:4:"cnic";s:13:"5540545612812";s:12:"home_address";s:9:"Scheme-33";s:16:"telephone_number";s:12:"923332654324";s:15:"registration_id";s:6:"08CS68";s:10:"program_id";s:1:"1";s:9:"cohort_id";s:1:"6";s:10:"section_id";s:1:"7";}
现在我想要一个 mysql 查询或一些内置的 wordpress 函数,借助它我可以过滤具有 registration_id
等于 08CS68
.
谢谢。
您可以使用 SUBSTRING_INDEX
:
registration_id
SELECT *
FROM yourtable
WHERE SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(_student_registration_data,
'registration_id', -1), ';', 2), ':', -1) = '"08CS68"'
尼克的回答是关键,但没有解决我的问题。这是实际起作用的:
SELECT * FROM (SELECT * FROM `cn_usermeta` WHERE meta_key = '_student_registration_data') as META WHERE SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(META.meta_value, 'registration_id', -1), ';', 2), ':', -1) = '"08CS68"'
特别感谢 Nick :)