Meta_query is not working on Elementor Custom Query Filter

admin2025-06-02  0

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 6 years ago.

Improve this question

I’m following this tutorial to create a custom query filter.

I would like to filter by a metadata created by ACF (Advanced Custom Field), but it seems not working for me.

My code is like this:

add_action('elementor_pro/posts/query/my_custom_qurery', function($query) {
    $searchStr = get_search_query();

    $meta_query = [
        'key' => 'codigo_de_barra',
        'value' => $searchStr,
        'compare' => '=',
    ];

    $query->set('meta_query', $meta_query);
    $query->set('post_type', 'produto');
});

I’m using the widget “Posts” to display the results and I’m sure that I have set the custom query to Custom ID field, because the post_type is affecting results when I change it.

Why meta_query is not working?

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 6 years ago.

Improve this question

I’m following this tutorial to create a custom query filter.

I would like to filter by a metadata created by ACF (Advanced Custom Field), but it seems not working for me.

My code is like this:

add_action('elementor_pro/posts/query/my_custom_qurery', function($query) {
    $searchStr = get_search_query();

    $meta_query = [
        'key' => 'codigo_de_barra',
        'value' => $searchStr,
        'compare' => '=',
    ];

    $query->set('meta_query', $meta_query);
    $query->set('post_type', 'produto');
});

I’m using the widget “Posts” to display the results and I’m sure that I have set the custom query to Custom ID field, because the post_type is affecting results when I change it.

Why meta_query is not working?

Share Improve this question asked Mar 3, 2019 at 14:36 Lai32290Lai32290 3512 gold badges4 silver badges15 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Meta query is an array containing arrays and not only one array (you can set multiple queries). So it should be:

$meta_query = [ [
    'key' => 'codigo_de_barra',
    'value' => $searchStr,
    'compare' => '=',
] ];
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748846023a314210.html

最新回复(0)