WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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() ) {

$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);

Now, when I manually add my 'book_type' to my url like this:


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.


Am I doing something wrong here?

Any help is appreciated. Thanks in advance!

share|improve this question
the link you give use checkbox in the code snippet – nonsensecreativity Jan 8 '14 at 22:13
No, that's a checkbox for the page template. To check/uncheck multiple choices on the front-end. I'm trying to use a Checkbox Field when they're using a Radio Field to retrieve the values. – realph Jan 8 '14 at 22:22
I've edited my original question above, to help explain the issue a little further. – realph Jan 9 '14 at 15:53
up vote 1 down vote accepted

If you're receiving an array, your meta_query is going to change. LIKE will no longer be valid, you'd need to do an IN comparison at that point.

Also I'm not entirely convinced you're correctly passing a $_GET array

share|improve this answer
I've tried an IN comparison, but no results are shown. I just get a blank page. – realph Jan 9 '14 at 16:22
If you get a blank page, you should check your logs for the error report... You do have debugging enabled, right? Also, updated answer. – GhostToast Jan 9 '14 at 16:24
I have debugging enabled. Not getting an error on the "?books=men" page, but am getting an "Undefined index" error in relation to the $_GET param I'm using on my archive page template. – realph Jan 9 '14 at 16:31
I've been trying to work out how to print that $_GET array, so I can check it. Can I not do it in Chrome's Console? Sorry for these silly questions, I'm still trying to wrap my head around PHP and this is my first time in the trenches. – realph Jan 9 '14 at 16:36
Chrome's console won't help with PHP, only javascript and CSS. Go read your logs, as you don't always get output – GhostToast Jan 9 '14 at 16:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.