WordPress.org

Ready to get started?Download WordPress

Forums

Add new category to multiple old posts (6 posts)

  1. The Painted Hive
    Member
    Posted 2 years ago #

    I am in the process of migrating my blog over from Blogger. I want to add some new categories to a few of my old posts to make my new site easier to navigate for readers (for example, I want to add a 'before and after' category to old posts previously filed under "furniture rehab' and 'room makeovers'). Is there a way to add new categories to multiple old posts without having to go in and manually add each one to each post (I have quite a few posts so this would be very laborious). Thanks.

  2. You might want to look at a plugin like http://wordpress.org/extend/plugins/bulk-move/

    or http://wordpress.org/extend/plugins/batch-cat/

    I personally haven't used them, so can't say for sure which one is best.

  3. deepbevel
    Member
    Posted 2 years ago #

    I'm stumped here, how could wp or a plugin know which posts go to which new categories?

  4. deepbevel
    Member
    Posted 2 years ago #

    however along those lines, here's a function code that can auto categorize based on post title. This example puts all posts with "orages" as title in a category called oranges:

    add_action( 'wp_insert_post', 'update_post_terms' );
    function update_post_terms( $post_id ) {
        if ( $parent = wp_is_post_revision( $post_id ) )
        $post_id = $parent;
        $post = get_post( $post_id );
        if ( $post->post_type != 'post' )
        return;
        $post_title = get_the_title();
        if (stripos($post_title, 'oranges')!==false) {
    
        // add a category
        $categories = wp_get_post_categories( $post_id );
        $newcat = get_term_by( 'name', 'oranges', 'category' );
        array_push( $categories, $newcat->term_id );
        wp_set_post_categories( $post_id, $categories );
    
        }
    
        }

    I tried it a long time go and it worked.

  5. ChrisRich
    Member
    Posted 2 years ago #

    I am in the process of migrating my blog over from Blogger. I want to add some new categories to a few of my old posts to make my new site easier to navigate for readers (for example, I want to add a 'before and after' category to old posts previously filed under "furniture rehab' and 'room makeovers'). Is there a way to add new categories to multiple old posts without having to go in and manually add each one to each post (I have quite a few posts so this would be very laborious). Thanks.

    What you have asked for would be very handy, though thus far I have not seen any functionality for it. You'd think you could filter by category and and do a bulk category change, but alas I guess not...sigh.

    sell textbooks

  6. deepbevel
    Member
    Posted 2 years ago #

    The above code might be adaptable to add an additioonal category based on the current category, but I wouldn't know.

    It's looking like trying to do this may be more involved than adding new categories manually.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags