Home › Forums › ACF PRO › Filters on custom taxonomy page › Reply To: Filters on custom taxonomy page
Another update… Turns out that the database can’t find any posts using the code examples from the documentation and it’s not possible to use the IN operator for checkboxes. I could only find results with the following SQL:
SELECT * FROM cms_posts INNER JOIN cms_postmeta ON( cms_posts.ID = cms_postmeta.post_id ) WHERE 1 = 1 AND( ( cms_postmeta.meta_key = 'pb_region' AND cms_postmeta.meta_value LIKE '%eu%' ) ) GROUP BY cms_posts.ID ORDER BY cms_posts.post_title ASC;
And the posts get filtered only if I set custom arguments in the template itself and manually setting the meta_query but not when using pre_get_posts
(I already checked if there was another instance overriding it, there isn’t).
This is the query when looping through a custom query and meta_query
defined with a string value:
WP_Query Object
(
[query] => Array
(
[post_type] => products
[orderby] => title
[order] => ASC
[posts_per_page] => -1
[tax_query] => Array
(
[taxonomy] => games
[term] => totk
)
[meta_query] => Array
(
[0] => Array
(
[key] => pb_region
[value] => eu
[compare] => LIKE
)
)
)
[query_vars] => Array
(
[post_type] => products
[orderby] => title
[order] => ASC
[posts_per_page] => -1
[tax_query] => Array
(
[taxonomy] => games
[term] => totk
)
[meta_query] => Array
(
[0] => Array
(
[key] => pb_region
[value] => eu
[compare] => LIKE
)
)
[...]
)
[...]
[meta_query] => WP_Meta_Query Object
(
[queries] => Array
(
[0] => Array
(
[key] => pb_region
[value] => eu
[compare] => LIKE
)
[relation] => OR
)
[relation] => AND
[meta_table] => cms_postmeta
[meta_id_column] => post_id
[primary_table] => cms_posts
[primary_id_column] => ID
[table_aliases:protected] => Array
(
[0] => cms_postmeta
)
[clauses:protected] => Array
(
[cms_postmeta] => Array
(
[key] => pb_region
[value] => eu
[compare] => LIKE
[compare_key] => =
[alias] => cms_postmeta
[cast] => CHAR
)
)
[has_or_relation:protected] =>
)
[...]
This is my current code, by the way:
$meta_query = array(
'key' => $name,
'value' => $value,
'compare' => 'LIKE'
);
Any input would be much appreciated.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We’re reaching out to our multilingual users to ask for help in translating ACF 6.1. Help make sure the latest features are available in your language here: https://t.co/TkEc2Exd6U
— Advanced Custom Fields (@wp_acf) May 22, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.