• I have installed the more fields plugin which gives me access to a custom field checkbox. When setting the field up through the plugin the caption says: Creates single checkbox, which key is either on/off. As you can see by the query I am looking for all the events whose event-archive = on.

    Is there a better way to do this? This doesn’t return any posts anyways. Is there a better way to build a boolean field?

    $archive_query = new WP_Query(
            array(
              'post_type'  => 'event',        // only query events
              'meta_key'    => 'event-archive',  // load up the event_date meta
              'order'       => 'desc',         // ascending, so earlier events first
              'posts_per_page' => '5',
              'meta_query'  => array(
                 array(         // restrict posts based on meta values
                  'key'     => 'event-archive',  // which meta to query
                  'value'   => 'on',  // value for comparison
                  'compare' => '=',          // method of comparison
                  'type'    => 'CHAR'         // datatype, we don't want to compare the string values
                 ) // meta_query is an array of query ites
                ) // end meta_query array
              ) // end array
            ); // close WP_Query constructor call

    The More-Fields plugin checkbox is returning a 1 if the checkbox is checked. But if I do key => event-archive, value => ‘1’, and compare => =, and type = numberic, it does not return any events. Even though I have an event with the box checked.

  • The topic ‘More Fields checkbox as a boolean isn't working’ is closed to new replies.