Support

Account

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.