0

I'm using ACF to create custom field of select type. I used like this to create custom select field like this:

1 : Anh
2 : Hai
3 : Hoang
4 : May
....
12 : Lan

I use this query to search posts have value is 1 (Anh) like this:

                 URL for query :   /?thename=1
                 $thename = $_GET['thename'];
                 $args = array(
                            'post_type' => 'interviews',
                            'post_status'    => 'publish',
                            'posts_per_page' => $perpage,
                            'paged'          => get_query_var('paged'),
                            'meta_query'    => array(
                                    'key'       => 'thename',
                                    'value'     => $thename,
                                    'compare'   => 'LIKE',
                                )

I searched like this but it returns wrong results. I think the value of thename field is array (value and label) then It is not possible to use query above.

So can you suggest me to do with this search? Thanks.

2 Answers 2

1

Your meta query should be an array within an array... update the meta_query like below:

'meta_query' => array(
    array(
        'key'       => 'thename',
        'value'     => $thename,
        'compare'   => 'LIKE',
    )
)
Sign up to request clarification or add additional context in comments.

Comments

1

According to the meta_query documentation meta_query must contains one or more arrays, so your query must be something look like this :

'meta_query' => [
  [
    'key'       => 'thename',
    'value'     => $thename,
    'compare'   => 'LIKE',
  ]
]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.