Remove Categories with bulk edit
-
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….Thanks
-
I think this is a really nice feature request.. I’m was actually looking for this and was not able to find anything..
Thanks
Thanks!It is indeed…
WordPress 2.9.1
Create admin-script.js in theme folder and edit:
jQuery(document).ready(function($){ $('.cat-checklist') .prepend( '<li><label class="selectit"><input value="1" type="checkbox" name="remove_categories" id="remove_categories"/> Remove Checked Categories</label></li>' ); });functions.php:
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']); unset($_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; wp_update_post($post_data); } } } } } add_action('check_admin_referer', 'my_bulk_edit', 10, 2);Check ‘Remove Checked Categories’ and categories you want to remove!
Hi kz:
I made the changes you indicated and now my blog is completely down. Please help.
Thanks,
JimDelete the changes from your theme (just removing the bit from functions.php should be enough).
I did that, but it still did not work. I ended up restoring my blog from a backup.
Was it the adding the code that broke it or the running of the code that broke it?
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?
Frelling brilliant. Thank you – You saved be about an hour and a half of combing thru posts!
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.
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!
The topic ‘Remove Categories with bulk edit’ is closed to new replies.