2

I'm trying to customize the Categories meta-box when adding a post.

screenshot

I have added a custom post and I need the administrator to post a new post without the ability to use the top level categories and also, he can just choose only one category, no more than one category!

6
  • function convert_root_cats_to_radio(){global $post_type; ?> <script type="text/javascript"> jQuery("#activitycategorychecklist>li>label input").each(function(){ this.disabled = "disabled"; }); jQuery("#activitycategorychecklist>li>ul>li>label input").each(function(){ this.type = 'radio'; }); jQuery("#activitycategory-tabs li:odd").hide(); </script> <?php} add_action( 'admin_footer-post.php', 'convert_root_cats_to_radio' ); add_action( 'admin_footer-post-new.php', 'convert_root_cats_to_radio' );
    – liying
    Commented Jan 3, 2013 at 9:50
  • I have solved as the code above ,thanx!
    – liying
    Commented Jan 3, 2013 at 9:50
  • 2
    Please add this as answer then. You can mark it as solved in two days. Help us helping you and later users with keeping the site clean.
    – kaiser
    Commented Jan 3, 2013 at 12:42
  • How to mark it as solved?
    – liying
    Commented Jan 6, 2013 at 6:19
  • Add it as answer, check back two days later, tick the check mark below the voting arrows. Thanks.
    – kaiser
    Commented Jan 6, 2013 at 6:56

2 Answers 2

5

Freed from comment; the asker really did not want to write an answer. :/

function convert_root_cats_to_radio()
{
    global $post_type; 
    ?> 
<script type="text/javascript"> 
jQuery("#activitycategorychecklist>li>label input").each(function(){ 
    this.disabled = "disabled"; 
}); 
jQuery("#activitycategorychecklist>li>ul>li>label input").each(function(){ 
    this.type = 'radio'; 
}); 
jQuery("#activitycategory-tabs li:odd").hide(); 
</script> <?php
} 
add_action( 'admin_footer-post.php',     'convert_root_cats_to_radio' ); 
add_action( 'admin_footer-post-new.php', 'convert_root_cats_to_radio' );
1

My Radio Buttons for Taxonomies plugin converts any taxonomy (including categories) to radio buttons so that only 1 term can ever be selected. Though I guess it doesn't handle restricting/disabling the top-level terms.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.