Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php meta_查询中的集合比较错误-wordpress_Php_Wordpress - Fatal编程技术网

Php meta_查询中的集合比较错误-wordpress

Php meta_查询中的集合比较错误-wordpress,php,wordpress,Php,Wordpress,复选框保存在db中 db结构(wp_Posteta表): ________________________________________________________________ | | | | meta_key | meta_value | |_______________|_______

复选框保存在db中

db结构(wp_Posteta表)

________________________________________________________________
|               |                                               |
|   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子句(.It将最终查找完全匹配的结果

您所做的更多的是搜索。您不知道您的数据集将落在序列化字符串的何处。对于这种类型的搜索,您应该使用
LIKE
操作符()。对于这种类型的搜索,您需要使用通配符标志


从我收集到的关于您存储的数据类型的信息来看,您可能需要重新考虑您的存储机制。自定义字段确实支持同一元键的多个值,这是一种快速方法。您还可以利用或自定义表()。

您确认了
序列化(数组($post->ID=>“$post->ID”))
实际返回的是您期望的结果吗?我找到了一种不同的方法,但我没有测试它。我认为我们应该像“标签”一样测试如果我们有一个键它可以工作,但不是当序列化1键时,在db 2中key51是艺术家的id,歌曲有1或2个艺术家。在每个帖子中,我们都有一个保存艺术家id的字段,在艺术家配置文件中,我们应该显示sonartistsYea的gs都是有意义的。每次只需将艺术家id存储在单独的字段中即可。请查看
get\u post\u meta()