如何从 WordPress 的 wp_postmeta table 中提取数据?
How to extract data from WordPress's wp_postmeta table?
我有一个 WordPress 网站,当一些用户填写表格时我想找到离他最近的 3 个用户并向他们发送电子邮件。
我认为在不编辑主题的情况下使用 WordPress 是不可能的,而且我对 WordPress 的经验不多。
所以我创建了一个带有自定义 PHP 的表单(不在 WordPress 中),它可以访问 WordPress 数据库,我正在尝试 select 3 个离用户位置最近的用户。
对于当前用户,我有邮政编码、城市、地址,对于其他用户,我有邮政编码、地址、纬度和经度存储在由 WordPress 序列化的数据库中。
我搜索了如何执行此操作并找到了 Haversine 公式。但它需要有纬度和经度值。
如何从这个wp_postmetatable中提取纬度和经度以获得最近的用户?
+------------------------------------------+
meta_id | post_id | meta_key | meta_value
+------------------------------------------+
12 | 25 | lp_options | a:32:{s:12:"tagline_text";s:36:"Legendary sushi maestro in your town";s:8:"gAddress";s:47:"86 East Pine Street, Seattle, WA, United States";s:8:"latitude";s:10:"47.6152846";s:9:"longitude";s:19:"-122.30498549999999";s:6:"mappin";s:0:"";s:5:"phone";s:14:"(206) 441-8844";s:8:"whatsapp";s:0:"";s:5:"email";s:27:"codewithdeveloper@gmail.com";s:7:"website";s:24:"http://sushikashiba.com/";s:7:"twitter";s:19:"https://example.com";s:8:"facebook";s:19:"https://example.com";s:8:"linkedin";s:19:"https://example.com";s:7:"youtube";s:19:"https://example.com";s:9:"instagram";s:19:"https://example.com";s:5:"video";s:43:"https://www.youtube.com/watch?v=oMxLKOv_3t0";s:7:"gallery";s:0:"";s:12:"price_status";s:14:"ultra_high_end";s:10:"list_price";s:0:"";s:13:"list_price_to";s:0:"";s:7:"Plan_id";s:1:"0";s:16:"lp_purchase_days";s:0:"";s:11:"reviews_ids";s:0:"";s:15:"claimed_section";s:11:"not_claimed";s:26:"listings_ads_purchase_date";s:0:"";s:30:"listings_ads_purchase_packages";s:0:"";s:4:"faqs";a:2:{s:3:"faq";a:2:{i:1;s:11:"Specialties";i:2;s:7:"History";}s:6:"faqans";a:2:{i:1;s:153:"Legendary sushi maestro, Chef Shiro Kashiba brings his authentic and innovative Edomae style of sushi and acclaimed Japanese cuisine to downtown Seattle.";i:2;s:226:"Chef Shiro Kashiba started Seattle's first sushi bar in 1970 after years of grueling training alongside world renown sushi chef Jiro Ohno in Tokyo. Chef Shiro Kashiba introduced his masterpiece, Sushi Kashiba in December 2015.";}}s:14:"business_hours";a:6:{s:6:"Monday";a:2:{s:4:"open";s:7:"02:00pm";s:5:"close";s:7:"11:00pm";}s:7:"Tuesday";a:2:{s:4:"open";s:7:"02:00pm";s:5:"close";s:7:"11:00pm";}s:9:"Wednesday";a:2:{s:4:"open";s:7:"02:00pm";s:5:"close";s:7:"11:00pm";}s:8:"Thursday";a:2:{s:4:"open";s:7:"02:00pm";s:5:"close";s:7:"11:00pm";}s:8:"Saturday";a:2:{s:4:"open";s:7:"02:00pm";s:5:"close";s:7:"11:00pm";}s:6:"Sunday";a:2:{s:4:"open";s:7:"02:00pm";s:5:"close";s:7:"11:00pm";}}s:11:"campaign_id";i:93;s:14:"changed_planid";s:0:"";s:19:"listing_reported_by";s:0:"";s:16:"listing_reported";s:0:"";s:13:"business_logo";s:0:"";
WordPress 使用 php 的 serialize() / unserialize() stuff to encode the data arrays it puts into its wp_postmeta table。 table 为实例上的每个 post 保存任意元数据的键/值对。
编码格式在概念上类似于JSON,但在句法上不同。
$lpOptions = unserialize( $thatStringStarting_a_32 );
给你一个数组,其中包含
这样的元素
$lpOptions['tagline_text']
$lpOptions['latitude']
$lpOptions['longitude']
和其他人。注意:如果 cybercreep 向您发送恶意制作的数据字符串,反序列化可能会把您搞得一团糟。
您是在 WordPress 模块(插件、模板)中对此进行编程吗?如果是这样,请使用 WordPress 核心 get_post_meta() function 从 MySQL.
获取此数据
$lpOptions = get_post_meta( $post_id, 'lp_options' );
我有一个 WordPress 网站,当一些用户填写表格时我想找到离他最近的 3 个用户并向他们发送电子邮件。
我认为在不编辑主题的情况下使用 WordPress 是不可能的,而且我对 WordPress 的经验不多。
所以我创建了一个带有自定义 PHP 的表单(不在 WordPress 中),它可以访问 WordPress 数据库,我正在尝试 select 3 个离用户位置最近的用户。
对于当前用户,我有邮政编码、城市、地址,对于其他用户,我有邮政编码、地址、纬度和经度存储在由 WordPress 序列化的数据库中。
我搜索了如何执行此操作并找到了 Haversine 公式。但它需要有纬度和经度值。
如何从这个wp_postmetatable中提取纬度和经度以获得最近的用户?
+------------------------------------------+
meta_id | post_id | meta_key | meta_value
+------------------------------------------+
12 | 25 | lp_options | a:32:{s:12:"tagline_text";s:36:"Legendary sushi maestro in your town";s:8:"gAddress";s:47:"86 East Pine Street, Seattle, WA, United States";s:8:"latitude";s:10:"47.6152846";s:9:"longitude";s:19:"-122.30498549999999";s:6:"mappin";s:0:"";s:5:"phone";s:14:"(206) 441-8844";s:8:"whatsapp";s:0:"";s:5:"email";s:27:"codewithdeveloper@gmail.com";s:7:"website";s:24:"http://sushikashiba.com/";s:7:"twitter";s:19:"https://example.com";s:8:"facebook";s:19:"https://example.com";s:8:"linkedin";s:19:"https://example.com";s:7:"youtube";s:19:"https://example.com";s:9:"instagram";s:19:"https://example.com";s:5:"video";s:43:"https://www.youtube.com/watch?v=oMxLKOv_3t0";s:7:"gallery";s:0:"";s:12:"price_status";s:14:"ultra_high_end";s:10:"list_price";s:0:"";s:13:"list_price_to";s:0:"";s:7:"Plan_id";s:1:"0";s:16:"lp_purchase_days";s:0:"";s:11:"reviews_ids";s:0:"";s:15:"claimed_section";s:11:"not_claimed";s:26:"listings_ads_purchase_date";s:0:"";s:30:"listings_ads_purchase_packages";s:0:"";s:4:"faqs";a:2:{s:3:"faq";a:2:{i:1;s:11:"Specialties";i:2;s:7:"History";}s:6:"faqans";a:2:{i:1;s:153:"Legendary sushi maestro, Chef Shiro Kashiba brings his authentic and innovative Edomae style of sushi and acclaimed Japanese cuisine to downtown Seattle.";i:2;s:226:"Chef Shiro Kashiba started Seattle's first sushi bar in 1970 after years of grueling training alongside world renown sushi chef Jiro Ohno in Tokyo. Chef Shiro Kashiba introduced his masterpiece, Sushi Kashiba in December 2015.";}}s:14:"business_hours";a:6:{s:6:"Monday";a:2:{s:4:"open";s:7:"02:00pm";s:5:"close";s:7:"11:00pm";}s:7:"Tuesday";a:2:{s:4:"open";s:7:"02:00pm";s:5:"close";s:7:"11:00pm";}s:9:"Wednesday";a:2:{s:4:"open";s:7:"02:00pm";s:5:"close";s:7:"11:00pm";}s:8:"Thursday";a:2:{s:4:"open";s:7:"02:00pm";s:5:"close";s:7:"11:00pm";}s:8:"Saturday";a:2:{s:4:"open";s:7:"02:00pm";s:5:"close";s:7:"11:00pm";}s:6:"Sunday";a:2:{s:4:"open";s:7:"02:00pm";s:5:"close";s:7:"11:00pm";}}s:11:"campaign_id";i:93;s:14:"changed_planid";s:0:"";s:19:"listing_reported_by";s:0:"";s:16:"listing_reported";s:0:"";s:13:"business_logo";s:0:"";
WordPress 使用 php 的 serialize() / unserialize() stuff to encode the data arrays it puts into its wp_postmeta table。 table 为实例上的每个 post 保存任意元数据的键/值对。
编码格式在概念上类似于JSON,但在句法上不同。
$lpOptions = unserialize( $thatStringStarting_a_32 );
给你一个数组,其中包含
这样的元素$lpOptions['tagline_text']
$lpOptions['latitude']
$lpOptions['longitude']
和其他人。注意:如果 cybercreep 向您发送恶意制作的数据字符串,反序列化可能会把您搞得一团糟。
您是在 WordPress 模块(插件、模板)中对此进行编程吗?如果是这样,请使用 WordPress 核心 get_post_meta() function 从 MySQL.
获取此数据$lpOptions = get_post_meta( $post_id, 'lp_options' );