WordPress.org

Support

Support » Plugins and Hacks » Select only one category

Select only one category

  • Hi,

    I’ve searched for a plugin or function to select only one category in the post-new section. I found a very old solution, that didn’t work. (was for WP 2.0 😉 ). http://wordpress.org/support/topic/help-create-a-simple-admin-plugin?replies=4

    So I made an update. Maybe someone can use it too:

    <?php
    /*
    Plugin name: One category only
    Version: 0.2
    Description: Replace the categories checkbox list in the admin area, by a radio button list, so that you choose only one category per post. Tested with WP 3.3.1.
    */
    if(strstr($_SERVER['REQUEST_URI'], 'wp-admin/post-new.php')) {
    ob_start('one_category_only');
    }
    function one_category_only($content) {
    $content = str_replace('type="checkbox" ', 'type="radio" ', $content);
    return $content;
    }
    ?>

    Thanx to PozHonks for that great idea!

    Greetz from Austria
    Achim

Viewing 3 replies - 1 through 3 (of 3 total)
  • thank you thank you thank you!

    i literally tried this old code 5 minutes ago, and it wasnt working, so i kept searching on, and this is what i found…

    why dont you submit it as plugin? i can do it if you dont want to

    i found big big bug…

    basically it changes ALL checkbox buttons into radio buttons

    every single one of them on that “create a post” page

    for example: this becomes radio buttons, and you CANNOT un-select them

    Allow comments.
     Allow trackbacks and pingbacks on this page.

    and if you edit post, there are still checkboxes not radio buttons

    thanks for the update

    @bizilux
    change

    if(strstr($_SERVER['REQUEST_URI'], 'wp-admin/post-new.php')) {

    to

    if(
    	strstr($_SERVER['REQUEST_URI'], 'wp-admin/post-new.php') ||
    	strstr($_SERVER['REQUEST_URI'], 'wp-admin/post.php')
    
    	)
    {

    @almstudio also greets from Austria

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Select only one category’ is closed to new replies.
Skip to toolbar