I've got a series of custom post types set up, and a large amount of custom fields are linked to these post types via the Advanced Custom Fields plugin.
I want to set up a series of checkboxes on the frontend to filter posts via their custom fields. This is what it looks like at the moment:
And here's the code I'm using to produce it on my archive-books.php page:
<?php $array = array('format', 'bedrooms', 'type'); ?> <?php foreach ($array as $value): $field = get_field_object($value); $values = explode(',', $_GET[$value]); ?> <div id="<?php echo $value; ?>" class="filter"> <h3><?php echo $value; ?></h3> <ul class="<?php echo $value; ?>"> <?php foreach( $field['choices'] as $choice_value => $choice_label ): ?> <li> <input type="checkbox" value="<?php echo $choice_value; ?>" <?php if( in_array($choice_value, $values) ): ?>checked="checked"<?php endif; ?> /> <?php echo $choice_label; ?></li> </li> <?php endforeach; ?> </ul> </div> <?php endforeach; ?>
$array. This also needs to take into account multiple filters, so the URL would look like this:
foreach loop, but no dice.
Any help is appreciated! Thanks.