Forums

[resolved] Add multiple posts to a new category retrospectively (6 posts)

  1. iansdell
    Member
    Posted 2 years ago #

    I have a blog with more than 3,000 posts, and I'd like to add all of them to a new category.

    Using WordPress's built-in bulk edit facility would mean applying the process to 214 'Edit Posts' pages, 15 posts at a time.

    Does anyone know of a less laborious way of achieving what I want to do?

    Thanks

  2. vtxyzzy
    Member
    Posted 2 years ago #

    BACK UP YOUR DATABASE FIRST!

    This SQL should do what you want (replace the 7 with the term_taxonomy_id of the new category):

    INSERT INTO wp_term_relationships
    (object_id,term_taxonomy_id,term_order)
    SELECT ID,7,0 FROM wp_posts
    where post_type = 'post'
    and post_status = 'publish'

    If the category order is important to you, replace the 0 with a number higher than the maximum number of categories assigned to any post to make this the last category.

  3. MichaelH
    Volunteer
    Posted 2 years ago #

    Not saying anything about the solution but just to point out that you can change the "Screen Options" Number of posts per page to 999 and thus bulk edit 'almost' a thousand posts at one time.

    With that said, I would certainly follow vtxyzzy's wise advise BACK UP YOUR DATABASE FIRST!

  4. vtxyzzy
    Member
    Posted 2 years ago #

    Thanks, Michael. That is a safer solution. It should automatically take care of the category order.

  5. iansdell
    Member
    Posted 2 years ago #

    Perfect ... thanks guys!

  6. henkholland
    Member
    Posted 2 years ago #

    Wow, never saw that one Michael.
    Note: it makes things quite slow on my older PC so OK for a one time operation but set it back later to 20 or something so that yo do not think that WP "freezes".

Topic Closed

This topic has been closed to new replies.

About this Topic