I'm using Advanced Custom Fields and have been following along with this tutorial on Creating a WP archive with Custom Field Filter. In their example, they're using Radio Button Field; I would like to use the Checkbox Field for a custom post type called 'book', as some of my books have more than one 'book_type' associated with them.
Field name: book_type
Field type: Checkbox Field
Choices: men, women, children, accessories
My functions.php
page looks like this:
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['book_type']) ) {
$book_format[] = array(
'key' => 'type',
'value' => $_GET['book_type'],
'compare' => 'LIKE',
);
}
$query->set('meta_query', $book_format);
return;
}
Now, when I manually add my 'book_type' to my url like this:
dev.com/books?=men
it successfully shows all books related to men. But when I add the '|' seperator, as you do with an array, I get a blank page.
dev.com/books?=men|women|accessories
Am I doing something wrong here?
Any help is appreciated. Thanks in advance!