Home › Forums › General Issues › Filtering Archives Using Checkbox Custom Fields › Reply To: Filtering Archives Using Checkbox Custom Fields
@elliot *Exhale* I feel to cry! After a whole day of staring at my functions.php, I think I may have finally cracked it!
add_action('pre_get_posts', 'my_pre_get_posts');
function my_pre_get_posts( $query ) {
if( is_admin() ) {
return;
}
$book_format = $query->get('meta_query');
if( !empty($_GET['type']) ) {
$book_format[] = array(
'key' => 'type',
'value' => $_GET['type'],
'compare' => 'LIKE',
);
}
$query->set('meta_query', $book_format);
return;
}
Now when I append this to my url:
dev.com/books?=home
it displays an archive of all my books with the ‘type’ of ‘home’. This is fantastic!
The only problem I’m having now is, separating these in the url with the ‘|’ character doesn’t seem to yield any results. Any idea why that might be happening, or is that normal?
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!
The most recent ACF Chat Friday featured a live demo of how to register CPTs directly in the plugin, one of our most requested features. Check out the summary below for a replay of the demo, and don’t forget to register for the next session! https://t.co/k2KQ3WWBAz
— Advanced Custom Fields (@wp_acf) March 9, 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.