Fellow PHP Guru's, I need your mad problem solving skillz...
I'll cut straight to the point (this may be a long post). I'm attempting to control a category navigation bar for WordPress. This is controlled by a series of checkboxes (one for each category) in the admin settings area.
Basically, the user selects the categories (via checkboxes) they want to show in the Navigation Bar.
For each category in the $website_categories array I want it to create a checkbox - That part is done and works perfectly! YEY.
Now for each checkbox selected I want it to add to the $options['category_navigation'] array key the ID of the category the checkbox corresponds to. If I where to print_r($options); it would look like this...
Array([category_navigation] => 1 7 5 3 8 14) where each number is the category_id of each category.
Here's the important part the code I've written:
add_settings_field('category_navigation', 'Category Navigation:', 'category_navigation_setting', basename(__FILE__), 'main_settings');
$options = get_option('website_options');
foreach ($website_categories as $category_id => $category_name )
echo "<div><input name='website_options[category_navigation]' type='checkbox' id='$category_id' value='$category_id' /> $category_name</div>";
Unfortunately with the code I have, it chooses the last checked checkbox in the foreach and puts the value for that in the $options['category_navigation'] key instead of all values of the boxes checked - This is obvious why, even to me. The problem I'm having is finding a way to simply append the value to the end of the string of values already stored in $options['category_navigation'].
There are also other things to consider...
a) It will only add it to the $options variable once I click 'Update Options' and post the form. So it means I have to click a checkbox and update one at a time.
b) I have no idea how to get the state of each checkbox (true, false) from the $options['category_navigation'] key so that it stays that way when the user comes back to the admin area - At the moment all the checkboxes return to null even though the database was updated.
If any of you guru's can help me out I'd hugely appreciate it! I'd like to finally get this theme ready so I can publish it! If you can't help me, then god behold I'll be stuck for days pondering the situation until I give up and scrap my newly-found career as a web developer. :lol:
Please, if you need any more information just ask.
Thanks! - Tom.