Bulk Add a Category or Tag to WordPress Posts Without Losing Others
To bulk add a category to posts in WordPress without touching the categories they already have, two things have to be right: the selection of posts, and the behaviour of the change. In WOLF you select the posts in the Filters tab and add the term in the Bulk Edit tab with the append behaviour. Append keeps every existing term and adds the new one. The same steps work for tags and for custom taxonomies of any post type.
Append, replace or remove: pick the right behaviour
Every taxonomy in the taxonomies section of the Bulk Edit tab has a term list and a behaviour drop-down with three options:
| Behaviour | What happens to each post | Use it to |
|---|---|---|
| append | The selected terms are added. Existing terms stay. | Add a category or tag to many posts |
| replace | The post gets exactly the selected terms. All others are removed. | Give all posts one exact set of terms |
| remove | The selected terms are taken off. Other terms stay. | Take one tag or category off many posts |
The usual mistake is replace when append was meant: the posts end up with only the new category. If it happened, revert the run in the History tab, which records taxonomy changes too. To move posts from category A to category B and keep their other categories, run two operations: append B, then remove A.
Replace with an empty term list clears a category-type (hierarchical) taxonomy completely, as described in detaching a taxonomy from posts. For tags, select the tags to delete and use remove.
Bulk add a category to posts, step by step
- Select the posts. Use the Filters tab (see the next section) and click Filter. For a handful of posts on the current page, tick their checkboxes instead. A selection always wins over the filter.
- Check the scope. The notice at the top of the Bulk Edit tab says Bulk editing will be applied to: the filtered posts, the selected ones, or all posts of the post type.
- Enable the taxonomy. Tick the checkbox next to Categories (or Tags, or your custom taxonomy) in the taxonomies section.
- Choose the terms. Pick one or more terms in the list. Child terms appear indented under their parents.
- Set the behaviour to append.
- Click Do Bulk Edit and confirm the dialog.
Appending a child category does not add its parent. WordPress treats them as two separate terms, so select both if your theme or menu lists posts by the parent category. Several taxonomies can be changed in one run: enable Categories and Tags together, each with its own terms and behaviour.
Select the right posts with the taxonomy filters
Each taxonomy in the Filters tab has a term list and an operator:
- OR: posts that have at least one of the selected terms.
- AND: posts that have all of the selected terms.
- NOT IN: posts that have none of the selected terms.
Text, date, author and status filters combine with them, so "drafts by one author in News that mention webinar" is a single filter.
Posts in child categories are not included
Filtering by a parent category finds only the posts that have the parent itself. Posts that are only in one of its child categories do not match. Select the child categories in the list too, or let the filter include children with this snippet:
/*
* WOLF Filters: filtering by a parent category also finds posts
* that are only in its child categories.
* Child theme functions.php or a code snippets plugin.
*/
add_filter('wpbe_filter_include_children', function ($include_children, $taxonomy) {
if ('category' === $taxonomy) {
return true;
}
return $include_children;
}, 10, 2);
Posts that have no category or no tags
Selecting every term with NOT IN works, but not with thousands of tags. WOLF has two hidden operators for this, EXISTS and NOT EXISTS. They filter by whether a post has any term of the taxonomy at all. Turn them on with one line, as described in the FAQ on filtering by taxonomy attachment:
// Child theme functions.php or a code snippets plugin
add_filter('wpbe_filter_taxonomies_exists_show', '__return_true');
Reload the WOLF page, leave the term list of that taxonomy empty, set the operator to NOT EXISTS and filter. For regular posts, keep in mind that WordPress gives a post saved without a category the default category, usually Uncategorized. Most "uncategorized" posts are therefore found by filtering for that term with OR. After you append the right category to them, remove Uncategorized with a second run that uses remove.
"In category A and B but not in C"
Between taxonomies the relation is always AND, and each taxonomy has one operator. So "in category A and category B but not in category C" cannot be one filter: AND and NOT IN would both be needed on Categories. Use a temporary tag to split it into two passes:
- Create a temporary tag such as
batch-tempunder Posts > Tags and reload the WOLF page. Filter Categories with AND and the terms A and B, and appendbatch-tempto the result. - Reset, then filter Categories with NOT IN and C, and Tags with OR and
batch-temp. Because taxonomies are joined with AND, this is exactly the set you want. Run your bulk edit on it. - Filter by
batch-tempalone, remove it with the remove behaviour, and delete the tag.
If the post type has no second taxonomy, a temporary text meta field filtered with EXACT (=) does the same job.
One post or a few selected posts
For a single post, click its taxonomy cell in the Posts Editor. A popup lists the terms with the current ones ticked. It has a Quick search field, a create new term link and a selected only switch. Tick the new category, keep the others and click Apply. Whatever is ticked becomes the post's full set of terms.
Binded editing is not an append. When you change the categories of one selected row, that row's complete set of terms is copied to every selected post, and their own categories are replaced. Use it when all selected posts should end up with identical terms. To add a category to selected posts and keep the rest, use the Bulk Edit tab with append: it works on the selection the same way.
Tags, custom taxonomies and other post types
The Bulk Edit tab lists every taxonomy registered for the current post type: tags, post formats, the categories of a portfolio or events plugin, or a taxonomy you created yourself (see adding custom taxonomies). Switch the post type on the tools panel and the taxonomy lists follow. The guide to bulk editing custom post types shows the wider picture. In the free version, taxonomies that cannot be changed in bulk are shown in red containers in the Bulk Edit tab.
If it does not work
- The posts lost their other categories: the behaviour was replace, or binded editing was on. Revert the run in the History tab and repeat it with append.
- Child categories cannot be ticked, or the term lists look wrong after a plugin update: the browser is still running the old scripts. Clear the site and browser caches, then reload the WOLF page with Ctrl+F5 (Cmd+Shift+R on a Mac).
- A new term is missing from the lists: the lists are built when the page loads. Reload the WOLF page after creating terms elsewhere.
- The filter finds fewer posts than expected: check for child categories (see above) and for other filters still set in the Filters tab. Reset clears them all.
- The category archive still shows the old list: clear the page cache.
If a taxonomy still does not behave as described, post the post type, the taxonomy and the filter you used on the WOLF support forum.