I am creating a taxonomy filter for WordPress archives. I have the checkboxes working so when selected they redirect the page to the correct URL based on the taxonomy slug. My problem is that after page reload the checkbox state resets to unchecked.
Here is my code:
<?php
$workoutmoves = get_terms('Exercise-Types', array('hide_empty' => 0));
?>
<?php if ($workoutmoves): ?>
<h5>Show Me</h5>
<ul class="no-bullet">
<?php foreach($workoutmoves AS $workoutmove): ?>
<li>
<input class="check_box" type="checkbox" value="<?php echo $workoutmove->slug; ?>"><?php echo $workoutmove->name; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
I thought of adding a php if statement into the input field and echoing ‘checked=”checked”‘ but I don’t know how to grab the correct data to identify if it should be set.
Any insights would be a huge help. Thanks.
You just need to get the current taxonomy term using
get_queried_object()
wp function and change your loop a like this:I am not 100% sure what you are doing. However, I believe you want to highlight the current page a user is on. You are going to need an if() to do this. I do not know what data you have available, presumably WP will have some way of giving you the page url, something like:
If you cannot find the url from WP, it can be found in PHP as $_SERVER[‘REQUEST_URI’];
#
Part 2:
This will give you an array like:
array( ‘arms’,’legs’,’back’ );
Then, I think (I am not familiar with WP), change the line in the code provided by Tom:
To:
Or to give you all of it:
I’d try the following.