【发布时间】:2015-01-24 22:37:00
【问题描述】:
Wordpress 数据库,这个有点卡住了。
我正在使用以下内容来获取当前用户的 ID。
$user_ID = get_current_user_id();
这会返回如下内容:
15
现在我尝试在 show_user_list 字段中查找 $user_ID 的匹配值,该字段中的数据存储在一个数组中。
看起来像这样:
a:2:{i:0;s:2:"29";i:1;s:2:"15";}
这是我正在运行的查询(连同一组条件):
global $wpdb; $result = $wpdb->get_results( "SELECT post_id FROM wp_postmeta WHERE show_user_list IN (' . implode(',', $user_ID) . ' AND post_type = 'show' AND post_status = 'publish'" );
然后我试图用这个来呼应匹配 post_id 的值:
foreach ( $result as $unique ) {
echo $unique->post_id;
}
但它没有返回任何东西。我知道我在处理数组时一定犯了一个错误,但我不知道我哪里出错了?
【问题讨论】:
标签: php mysql arrays wordpress