ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

How/Can I merge categories?

July 30, 2009 1:28pm

Subscribe [1]
  • #1 / Jul 30, 2009 1:28pm

    4flix

    88 posts

    I have a bunch of categories that I would love to merge together.  Is there an easy way to do it, or do I need to so a search/replace via SQL (and where?).


    Thanks

  • #2 / Jul 30, 2009 1:47pm

    ChiefAlchemist

    913 posts

    It would seem that doing the SQL would be a sure bet.

    Another possibility *might be* (read: This is just theory. You can think about it and try it, I have not done it).

    There’s a setting in the Admin area that basically forces child categories to also take on the category of the parent.

    If you make the categories the child of the merge to (parent) category then those categories should now also come up when using the parent category.

    Obviously, there are some caveats here but this might be a quick / simple work around. What’s nice is you don’t lose the original categories in case the decider decides back again 😊

  • #3 / Jul 30, 2009 2:00pm

    ChiefAlchemist

    913 posts

    Opps. Forgot to add…

    Another question is… If you go back and delete the child, will the Parent setting say?

    If so, and that’s what you want / need to do (i.e., totally remove) then this little juggling act should keep you out of the SQL biz 😊

  • #4 / Jul 30, 2009 2:06pm

    Lisa Wess

    20502 posts

    It’s not just a matter of changing the category name, you’ll need to change the category ID and in several locations.  If you do this, I highly recommend doing so on a development server with plenty of backups.

  • #5 / Jul 30, 2009 2:20pm

    ChiefAlchemist

    913 posts

    Lisa you might know…

    If he forces the Use Parent… Make the merge / delete candidates a child. And then deletes the child… Will the Parent relationship still be there?

    If so, isn’t that the way to go? Other than a SQL find… Add… Delete…

  • #6 / Jul 30, 2009 2:36pm

    ender

    1644 posts

    As I recall the parent/child category thing only gets updated when the entry itself is saved.  So you could probably move the categories around but you’d still have to go into every entry and hit submit.

    As for the SQL statement to do this… if all you want to do is make all entries within one category into entries of the other category:

    UPDATE exp_category_posts SET cat_id='##cat_id_new##' WHERE cat_id='##cat_id_old##';

    totally untested, but I would think it should work.  The one thing you might have to watch out for is the entries that are already members of the category you’re trying to move them all into, as that would create a duplicate record and I assume mysql has unique keys on those entries.

    definitely back up the DB before messing with this.

  • #7 / Jul 30, 2009 2:39pm

    4flix

    88 posts

    Wow, thanks for all the suggestions.

    What’s going on is that I am using 1 weblog as a business directory.  There are just over 2000 businesses with 1295 categories.  The categories are over complex for what I have in mind for the site. 

    I have all the directory information in a CSV file and have done a successful import via CSV Grab.  I am thinking that I will have to go back to the CSV file and search/replace/delete the categories there.  Or..duplicate the categories column in the CSV file, search find and delete one of the duplicate columns to condense cats, and using the other duplicated column for tags.

    I would be curious the method cheifAlchemist outlined would work tho, if anyhting for cleaning up after the fact.

  • #8 / Jul 30, 2009 2:58pm

    ChiefAlchemist

    913 posts

    Hey Kevin…

    Call me a squirrel (hording) or an elephant (never forgetting) but getting rid of data always makes me “nervous”. Especially someone is bound to say “Remember when…”

    While 1,200 is a lot it’s not 12,000. Assuming you have everything already imported and in place, I would just make up a bunch a parents and then go back and assign each category you have now to a parent. Open it, pick the parent, save. Next… Not very exciting but it can be done. AND you still have an additional level of detail if you need it. But for the most part just deal with the parents, no?

    Note: The category names can repeat but the category URLs must be unique. I think.

    As for my theory… Either try it out on a dev install, or wait for Lisa to reply. Something tells me this approach is a bit unorthodox (read: It’s a functionality hack of sorts, certainly not the intention of the features being manipulated) so no matter what anyone else sez I’d test it out myself just to be safe 😊

    If you do test it please post what you find.

    MFS

  • #9 / Jul 30, 2009 3:18pm

    4flix

    88 posts

    Hi ChiefAlchemist -

    I completely understand about keeping the data, but since this is on a dev install AND is the only weblog in the install (plus I have backups of both the database and the CSV file), I’m not too concerned.  This is a personal project so the only person I have to answer to is my wife…and myself.

    I have found a great tool to edit the CSV file at http://csved.sjfrancke.nl/

    Right now I’m in OmniOutliner getting all the categories in order.  Thank god it’s not 12,000! 

    Thank you for your help

  • #10 / Jul 30, 2009 3:34pm

    4flix

    88 posts

    ChiefAlchemist -

    I tried what you had mentioned and it doesn’t work.

    I had a category, assigned a weblog entry to it.
    I then made a new category and assigned the category with the entry as a child.
    I deleted the child category and the entry didn’t default back to the parent.

    Yes, the option to assign items in a child category to it’s parent is on.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases