db !
数据库结构(wp_postmeta table):________________________________________________________________
| | |
| meta_key | meta_value |
|_______________|_______________________________________________|
| | |
| artist_nameaa | a:2:{i:51;s:2:"51";i:60;s:2:"60";} |
|_______________|_______________________________________________|
两个复选框已被选中!
我想找到职位,其中artist_nameaa
有51
键在他的数组
51是一个例子
这是我的尝试:
wp_reset_postdata();
global $post;
$args = array(
'post_type' => 'songs',
'meta_query' => array(
array(
'key' => 'artist_nameaa',
'value' => serialize(array($post->ID=>"$post->ID")),// a:1:{i:51;s:2:"51";}
'compare' => 'IN'
)
),
'no_found_rows' => true,
'update_post_meta_cache' => false,
'update_post_term_cache' => false,
'ignore_sticky_posts' => 1,
'post__not_in' => array($post->ID),
'posts_per_page' => -1
);
$query = new WP_Query($args);
return $query;
IN()
比较运算符用于替换几个where子句(docs)。它最终将寻找完全匹配的结果。
你所做的更多的是搜索。您不知道您的数据集将落在序列化字符串的哪个位置。对于这种类型的搜索,应该使用LIKE
操作符(docs)。对于这种类型的搜索,您需要使用通配符标志。
从我所收集到的你所存储的数据类型来看,你可能需要重新考虑你的存储机制。自定义字段确实支持同一元键的多个值,这将是一种快速的方法。您还可以利用自定义帖子类型或自定义表(wpdb)。