WordPress.org

Ready to get started?Download WordPress

Forums

Select only one category (4 posts)

  1. Achim Meurer
    Member
    Posted 2 years ago #

    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

  2. bizilux
    Member
    Posted 2 years ago #

    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

  3. bizilux
    Member
    Posted 2 years ago #

    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

  4. daveleeone
    Member
    Posted 1 year ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic