I’m at a loss with this. Do you see anything wrong with the code below specific to the noindex, nofollow checkboxes? The meta box gets drawn to the screen fine, but the values do not stick.
The code for the custom page title and custom excerpt works fine.
// ===================
// = POST OPTION BOX =
// ===================
add_action('admin_menu', 'my_post_options_box');
function my_post_options_box() {
if ( function_exists('add_meta_box') ) {
add_meta_box('post_header', 'Custom Post Header Code (optional)', 'custom_post_images', 'post', 'normal', 'low');
add_meta_box('post_title', 'Custom Post Title', 'custom_post_title', 'post', 'normal', 'high');
add_meta_box('post_title_page', 'Custom Post Title', 'custom_post_title_page', 'page', 'normal', 'high');
add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', 'page', 'normal', 'core');
add_meta_box('categorydiv', __('Page Index Options'), 'post_categories_meta_box_modified', 'page', 'side', 'high');
}
}
//Adds the custom images box
function custom_post_images() {
global $post;
?>
<div class="inside">
<textarea style="height:70px; width:100%;margin-left:-5px;" name="cb2_customHeader" id="cb2_customHeader"><?php echo get_post_meta($post->ID, 'cb2_customHeader', true); ?></textarea>
<p>Enter your custom html code here for the post page header/image area. Whatever you enter here will override the default post header or image listing <b>for this post only</b>. You can enter image references like so <img src='wp-content/uploads/product1.jpg' />. To show default images, just leave this field empty</p>
</div>
<?php
}
//Adds the custom post title box to posts
function custom_post_title() {
global $post;
?>
<div class="inside">
<p><input style="height:25px;width:100%;margin-left:-10px;" type="text" name="cb2_customTitle" id="cb2_customTitle" value="<?php echo get_post_meta($post->ID, 'cb2_customTitle', true); ?>"></p>
<p>Enter your custom Post Title here and it will be used for the html <title> for this post page and the Google link text used for this page.</p>
</div>
<?php
}
//Adds the custom post title box to pages
function custom_post_title_page() {
global $post;
?>
<div class="inside">
<p><input style="height:25px;width:100%;margin-left:-10px;" type="text" name="cb2_customTitle" id="cb2_customTitle" value="<?php echo get_post_meta($post->ID, 'cb2_customTitle', true); ?>"></p>
<p>Enter your custom Page Title here and it will be used for the html <title> for this page and the Google link text used for this page.</p>
</div>
<?php
}
//adds the custom categories box
function post_categories_meta_box_modified($post) {
global $post, $noindexCat, $nofollowCat;
$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>
<li id='category-1' class="popular-category" style="display:none;"><label class="selectit"><input value="1" type="checkbox" name="post_category[]" id="in-category-1" checked="checked"/> Uncategorized</label></li>
</ul>
</div>
<?php
}
add_action('save_post', 'custom_add_save');
function custom_add_save($postID){
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $postID;
}
else
{
// called after a post or page is saved
if($parent_id = wp_is_post_revision($postID))
{
$postID = $parent_id;
}
if ($_POST['cb2_customHeader'])
{
update_custom_meta($postID, $_POST['cb2_customHeader'], 'cb2_customHeader');
}
else
{
update_custom_meta($postID, '', 'cb2_customHeader');
}
if ($_POST['cb2_customTitle'])
{
update_custom_meta($postID, $_POST['cb2_customTitle'], 'cb2_customTitle');
}
else
{
update_custom_meta($postID, '', 'cb2_customTitle');
}
}
}
function update_custom_meta($postID, $newvalue, $field_name) {
update_post_meta($postID, $field_name, $newvalue);
}
I’m not sure but I think the simple answer is you have not yet added
"noindex"
and"nofollow"
as categories to your site. Go to the category page in the admin and add them and then I think your code will work, it did for me:Of course if you need to add those categories programmatically, ideally for use in a plugin activation so it only ever has to run when the plugin is first activated you can use the following code:
UPDATE:
@Scott B: Is it possible that you never associated the
category
taxonomy with thepage
post type? You know that Pages (post_type='page'
) don’t get categories by default, right? Somewhere in your code you need to runregister_taxonomy_for_object_type()
; my guess is you haven’t?If I’m right then adding this to your code will almost certainly solve your problem:
Hmm, maybe this is totally far away, but you are not saving the checkbox values in your saving hook, aren’t you?
btw: update will create if not exists. so no need for the if in that function. in the end no need for the helper function. less complexity will probably solving your issue easier.