在相似比较中具有多个元值的单个元键

时间:2015-09-30 作者:Gorakh Shrestha

我如何用单个元键搜索帖子,但在相似的比较中可能有多个元值。

这是我的查询帖子数组。

Array(
    [post_type] => post
    [posts_per_page] => 3
    [order] => DESC
    [meta_query] => Array(
        [relation] => AND
        [0] => Array(
                [key] => argomento
                [value] => Array(
                        [0] => 2875
                        [1] => 2884
                        [2] => 2877
                        [3] => 2957
                        [4] => 2959
                        [5] => 9628
                        [6] => 3203
                        [7] => 2952
                        [8] => 2947
                        [9] => 2961
                        [10] => 2955
                        [11] => 2950
                        [12] => 2881
                        [13] => 2879
                    )
                [compare] => like
            )
        [1] => Array(
                [key] => geo
                [value] => Array(
                        [0] => 2853
                        [1] => 20914
                        [2] => 2997
                        [3] => 13926
                        [4] => 14037
                        [5] => 2995
                        [6] => 12949
                        [7] => 7622
                    )
                [compare] => LIKE
            )
    )
 )
提前谢谢。

1 个回复
最合适的回答,由SO网友:Gorakh Shrestha 整理而成

我解决这个问题如下。我们应该比较每个元值,而不是在元值中传递数组。

Array(
    [post_type] => post
    [posts_per_page] => 3
    [order] => DESC
    [meta_query] => Array(
        [relation] => AND
        [0] => Array(
                [key] => argomento
                [value] => Array([0] => 2875 )
                [compare] => like
            )
        [1] => Array(
                [key] => argomento
                [value] => Array([0] => 2884 )
                [compare] => like
            )
        [2] => Array(
                [key] => argomento
                [value] => Array([0] => 2877 )
                [compare] => like
            )        
        [3] => Array(
                [key] => geo
                [value] => Array([0] => 2853 )
                [compare] => LIKE
            )
    )
 )
谢谢

相关推荐