Wordpress:使用get_results检查数据

时间:2018-05-01 09:33:34

标签: sql wordpress

我有问题检查数据是否找到,Bellow我在Wordpress中有一个表(postmeta),并存储数据如:

meta_id    : 27327
post_id    : 4876
meta_key   : rtb
meta_value : a:20:{s:5:"party";i:1;s:5:"email";s:18:"test@gmail.com";s:5:"phone";s:10:"05921655517";s:8:"catofres";s:6:"single";s:9:"tabletype";s:8:"openarea";s:14:"validationcode";i:8407704;s:11:"frindsname1";s:0:"";s:13:"frindsmobile1";s:0:"";s:11:"frindsname2";s:0:"";s:13:"frindsmobile2";s:0:"";s:11:"frindsname3";s:0:"";s:13:"frindsmobile3";s:0:"";s:11:"frindsname4";s:0:"";s:13:"frindsmobile4";s:0:"";s:11:"frindsname5";s:0:"";s:13:"frindsmobile5";s:0:"";s:11:"frindsname6";s:0:"";s:13:"frindsmobile6";s:0:"";s:15:"date_submission";i:1525176468;s:2:"ip";s:10:"37.8.85.11";}

现在问题怎么做SQL查询检查数据(test@gmail.com,8407704)是否发现了这个表,

我尝试这个查询:

$results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}postmeta WHERE `meta_key` = 'rtb' ", OBJECT );

但我无法完成查询

中的检查

1 个答案:

答案 0 :(得分:0)

global $wpdb;

$metas = $wpdb->get_results( 
 $wpdb->prepare("SELECT meta_value FROM $wpdb->postmeta where meta_key = %s", 'rtb')
 );

print_r($metas);

也试试

   if ( metadata_exists( 'post', $post_id, 'rtb' ) ) {
   $meta_value = get_post_meta( $post_id, 'rtb', true );
    }