• emzdesign

    (@emzdesign)


    Hi

    I have a site that has a lot of members and I want to change the post new page so that the categories are radio buttons rather than check boxes, so that they can only choose one category for their post to go into.

    I’ve tried modifying some functions (wp_dropdown_categories) but nothing I do seems to effect the post new page.

    Does anyone have any ideas or is there a plugin that allows you to do this?

    Thanks in advance.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter emzdesign

    (@emzdesign)

    Can anyone help me? Thanks.

    I want to do that too. My site has many members. It will be messy if they select many categories at once to boast up their postings.

    i want to do that too… but stil i couldnt fing

    I just actually figured out how to do this with JavaScript, I was looking at the same problem.

    In your functions.php:

    add_action( 'admin_footer', 'catlist2radio' );
    function catlist2radio(){
    	echo '<script type="text/javascript">';
    	echo 'jQuery("#categorychecklist input, #categorychecklist-pop input, .cat-checklist input")';
    	echo '.each(function(){this.type="radio"});</script>';
    }

    How/why it works: Insert a script in the footer of all admin pages. It uses jQuery (already present) to change the type of those inputs to radio which by default in the browser only allows 1 to be selected. There are 3 places where that list shows up, the new/edit post page (x2) and in quick edit mode. If there are more, we just need to find the DOM selector for it and add it to that list. That ought to take care of it!

    donzacharias, You just save my life… God Bless You

    Your a genius Don! Thanks so much!

    Now I’ve tried Don’s code and tweak it a little more like this:

    <?php
    function the_user_level () {
    	if (is_user_logged_in()) {
    		global $current_user, $wpdb;
    		$userLevel = $wpdb->get_var("SELECT meta_value FROM $wpdb->usermeta WHERE user_id=$current_user->id AND meta_key='wp_user_level'");
    		return $userLevel;
    	} else {
    		return 0;
    	}
    }
    ?>
    <?php
        $accessLevel = the_user_level();
        if ($accessLevel < 8) {
    add_action( 'admin_footer', 'catlist2radio' );
    function catlist2radio(){
    	echo '<script type="text/javascript">';
    	echo 'jQuery("#categorychecklist input, #categorychecklist-pop input, .cat-checklist input")';
    	echo '.each(function(){this.type="radio"});</script>';
    }
     }else {
    	echo '';
        }
    ?>

    The idea is, I want all user with level less then 8 (editor – subscriber) have to choose category with radio button, while admin still allowed to pick more then 1 cats per post with checkboxes.

    The problem is, it works well with FF, Opera, & Safari but in IE, checkbox appeared again.

    Please help

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Making category selection radio buttons’ is closed to new replies.