0

当一些用户填写表格时,我有一个 WordPress 网站,我想找到离他最近的 3 个用户并向他们发送电子邮件。

我认为不编辑主题就不可能使用 WordPress,而且我对 WordPress 没有太多经验。

因此,我使用自定义 PHP(不在 WordPress 中)创建了一个可以访问 WordPress 数据库的表单,并且我正在尝试选择离用户位置最近的 3 个用户。

对于当前用户,我有邮政编码、城市、地址,对于其他用户,我有邮政编码、地址、纬度和经度存储在由 WordPress 序列化的数据库中。

我已经搜索了如何执行此操作并找到了 Haversine 公式。但它需要有纬度和经度值。

如何从此 wp_postmeta 表中提取纬度和经度以获取最近的用户?

+------------------------------------------+
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:"";
4

1 回答 1

0

WordPress 使用 php 的serialize() / unserialize()东西来编码它放入wp_postmeta 表的数据数组。该表包含实例上每个帖子的任意元数据的键/值对。

编码格式在概念上类似于 JSON,但在语法上有所不同。

$lpOptions = unserialize( $thatStringStarting_a_32 );

为您提供一个包含以下元素的数组

$lpOptions['tagline_text']
$lpOptions['latitude']
$lpOptions['longitude']

和别的。小心:如果网络蠕虫向您发送恶意制作的数据字符串,反序列化可能会搞砸您。

您是否在 WordPress 模块(插件、模板)中对此进行编程?如果是这样,请使用 WordPress 核心get_post_meta() 函数从 MySQL 获取此数据。

$lpOptions = get_post_meta( $post_id, 'lp_options' );
于 2020-11-10T22:42:32.370 回答