What's wrong with this code? Values not saved to db
Posted
by Scott B
on Stack Overflow
See other posts from Stack Overflow
or by Scott B
Published on 2010-03-29T19:22:48Z
Indexed on
2010/03/29
19:43 UTC
Read the original article
Hit count: 280
Been trying to get this code to work for several days now to no avail. I'm at wits end. I've managed, with the code below, to create a customized category picker widget that appears on the PAGE editor. However, for the life of me, I cannot get the checked categories to save.
function my_post_options_box() {
if ( function_exists('add_meta_box') ) {
//add_meta_box( $id, $title, $callback, $page, $context, $priority );
add_meta_box('categorydiv', __('Page Options'), 'post_categories_meta_box_modified', 'page', 'side', 'core');
}
}
//adds the custom categories box
function post_categories_meta_box_modified($post) {
$noindexCat = get_cat_ID('noindex');
$nofollowCat = get_cat_ID('nofollow');
if(in_category("noindex")){ $noindexChecked = " checked='checked'";} else {$noindexChecked = "";}
if(in_category("nofollow")){ $nofollowChecked = " checked='checked'";} else {$noindexChecked = "";}
?>
<div id="categories-all" class="ui-tabs-panel">
<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
<li id='category-<?php echo $noindexCat ?>' class="popular-category"><label class="selectit"><input value="<?php echo $noindexCat ?>" type="checkbox" name="post_category[]" id="in-category-<?php echo $noindexCat ?>"<?php echo $noindexChecked ?> /> noindex</label></li>
<li id='category-<?php echo $nofollowCat ?>' class="popular-category"><label class="selectit"><input value="<?php echo $noindexCat ?>" type="checkbox" name="post_category[]" id="in-category-<?php echo $nofollowCat ?>"<?php echo $nofollowChecked ?> /> nofollow</label></li>
<li id='category-1' class="popular-category"><label class="selectit"><input value="1" type="checkbox" name="post_category[]" id="in-category-1" checked="checked"/> Uncategorized</label></li>
</ul>
</div>
<?php
}
© Stack Overflow or respective owner