Remove Categories with bulk edit (12 posts)

  1. substitute
    Posted 5 years ago #

    It's only possible to "add" new categories to more than one post using "bulk edit".
    I'd need to be able to remove a category from more than one file.
    I run an aggregator I have more than 2000 posts and sometimes FeddWP assign a wrong category to a huge amount of posts that I have to edit manually sigh....


  2. RoelofAlbers
    Posted 5 years ago #

    I think this is a really nice feature request.. I'm was actually looking for this and was not able to find anything..


  3. substitute
    Posted 5 years ago #

    Thanks!It is indeed...

  4. kz
    Posted 5 years ago #

    WordPress 2.9.1

    Create admin-script.js in theme folder and edit:

          '<li><label class="selectit"><input value="1" type="checkbox" name="remove_categories" id="remove_categories"/> Remove Checked Categories</label></li>'


    function my_enqueue() {
      wp_enqueue_script('my_admin_script', get_bloginfo('template_url') . '/admin-script.js', array('jquery'), false, true);
    add_action('admin_init', 'my_enqueue');
    function my_bulk_edit($action, $result){
      if('bulk-posts' == $action && isset($_GET['remove_categories']) && isset($_GET['post_category'])){
        if(($_GET['action'] != -1 || $_GET['action2'] != -1 ) && ( isset($_GET['post']) || isset($_GET['ids']))){
          $post_ids = isset($_GET['post']) ? array_map( 'intval', (array) $_GET['post'] ) : explode(',', $_GET['ids']);
          $doaction = ($_GET['action'] != -1) ? $_GET['action'] : $_GET['action2'];
        if('edit' == $doaction){
          if(isset($_GET['post_type']) && 'page' == $_GET['post_type']){
            if(! current_user_can('edit_pages'))
              wp_die( __('You are not allowed to edit pages.'));
          } else {
            if(! current_user_can( 'edit_posts' ))
              wp_die( __('You are not allowed to edit posts.'));
          $post_IDs = array_map('intval', (array) $_GET['post']);
          if(is_array($_GET['post_category']) && ! empty($_GET['post_category'])){
            $remove_cats = array_map('absint', $_GET['post_category']);
            foreach($post_IDs as $post_ID){
              if(wp_check_post_lock($post_ID)) continue;
              $cats = (array) wp_get_post_categories($post_ID);
              $post_data['post_category'] = array_diff($cats, $remove_cats);
              $post_data['ID'] = $post_ID;
    add_action('check_admin_referer', 'my_bulk_edit', 10, 2);

    Check 'Remove Checked Categories' and categories you want to remove!

  5. jwmccormack
    Posted 5 years ago #

    Hi kz:

    I made the changes you indicated and now my blog is completely down. Please help.


  6. Delete the changes from your theme (just removing the bit from functions.php should be enough).

  7. jwmccormack
    Posted 5 years ago #

    I did that, but it still did not work. I ended up restoring my blog from a backup.

  8. Was it the adding the code that broke it or the running of the code that broke it?

  9. jwmccormack
    Posted 5 years ago #

    I redid the actions above and now the blog is working. I must have accidentally pasted over something before. However, when I try to use the bulk categories remover it does not remove anything. Any thoughts?

  10. indiebookman
    Posted 5 years ago #

    Frelling brilliant. Thank you - You saved be about an hour and a half of combing thru posts!

  11. tmcmurry@zagat.com
    Posted 5 years ago #

    I just noticed a problem with the sample code. Unfortunately I don't know anything about JavaScript so I can't fix it.

    The problem condition: *if* a category name is alphabetically sorted below the category "uncategorized" (for example, Washington DC is after Uncategorized), *then* the bulk delete function will not remove the "uncategorized" category from the posts.

    I'm running wordpress-MU 2.9.1 (for the time being). 2.9.2 is now out.

  12. catnip216
    Posted 5 years ago #

    Takes me to a blank white page after I hit "Update", but when I go back to the post listing & refreshed the page, I see that it did do it's job. Thanks for the script!

Topic Closed

This topic has been closed to new replies.

About this Topic