Home › Forums › General Issues › Filtering Archives Using Checkbox Custom Fields › Reply To: Filtering Archives Using Checkbox Custom Fields
Ok, false alarm. The code above was wrong. @elliot Some people over on the Stack Exchange forum are saying I shouldn’t be using a LIKE compare, and an IN instead when using arrays.
Not sure which is right. But when I try to use an IN compare, I get a blank page when querying my posts.
add_action('pre_get_posts', 'my_pre_get_posts');
function my_pre_get_posts( $query ) {
if( is_admin() ) {
return;
}
$meta_query = $query->get('meta_query');
if( !empty($_GET['type']) ) {
$type = explode('|', $_GET['type']);
$meta_query[] = array(
'key' => 'type',
'value' => $type,
'compare' => 'IN',
);
}
$query->set('meta_query', $meta_query);
return; // always return
}
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 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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.