1

How can I search posts with single meta key but possible multiple meta value in like comparison.

Here is my array for query post.

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
            )
    )
 )

Thanks in advance.

  • What is that output you pasted? – cfx Sep 30 '15 at 4:21
  • This query post fetch post but not like as I want to filter. I need post which contain those id in meta value – Gorakh Shrestha Sep 30 '15 at 4:33
  • I still do not understand what you are currently doing and what the results are compared to what you want. Please clarify. – cfx Sep 30 '15 at 12:22
1

I solve this problem as below. We should compare each meta value instead of passing array in the meta value.

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
            )
    )
 )

Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.