WordPress > Cannot get custom meta settings to change once set...

Posted by Scott B on Stack Overflow See other posts from Stack Overflow or by Scott B
Published on 2010-03-29T14:20:18Z Indexed on 2010/03/29 15:03 UTC
Read the original article Hit count: 141

Filed under:
|

The script below adds a custom meta box to the WordPress page editor interface. It lists two specific categories, "noindex" and "nofollow", which my custom theme automatically installs when the theme is activated.

It works fine for selecting and assigning the categories to the page. However, if the user unchecks either of them, the settings do not stick. Once selected, they cannot be removed from the page, regardless if they are unchecked when the page is saved.

<?php
function my_post_categories_meta_box() {
   add_meta_box('categorydiv', __('Page Options'), 'post_categories_meta_box_modified', 'page', 'side', 'core');
}

function post_categories_meta_box_modified($post) {
    $noindexCat = get_cat_ID('noindex');
    $nofollowCat = get_cat_ID('nofollow');
    if(in_category("noindex")){ $noindexChecked = " checked='checked'";}
    if(in_category("nofollow")){ $nofollowChecked = " checked='checked'";}
?>
<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 $nofollowCat ?>" type="checkbox" name="post_category[]" id="in-category-<?php echo $nofollowCat ?>"<?php echo $nofollowChecked ?> /> nofollow</label></li> 
    </ul>
</div>
<?php
}
add_action('admin_menu', 'my_post_categories_meta_box');
?>

© Stack Overflow or respective owner

Related posts about php

Related posts about Wordpress