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 questionI’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 questionI’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?
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' => '=',
] ];