Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Peter Aderhold 30 posts 204 karma points
    Nov 28, 2019 @ 12:26
    Peter Aderhold
    0

    How to remove all tags (for not existing content)

    Hi Folks,

    I've created a lot of blog articles and saved a bunch of tags for them programatically. Then I deleted all of these articles.

    The problem is: all the tags are still existing.

    I didn't found out how to remove them.

    This will not work...

    var content = Services.ContentService.GetById(1234);
    var allTags = Umbraco.TagQuery.GetAllTags("BlogArticleTags", _culture).Select(x => x.Text);
    content.RemoveTags("BlogArticleTags", allTags, _culture);
    

    ...with ID of corresponding DataType (based on Umbraco.Tags). Content is always null - and the initially created content doesn't exists anymore, so I have no ID to use.

    It is strange that umbraco holds all these tags even with no corresponding content, or is there something I misunderstand?

    Any ideas how to solve this?

    Thank you very much!

    Peter

  • Peter Aderhold 30 posts 204 karma points
    Nov 28, 2019 @ 13:23
    Peter Aderhold
    0

    I've got it.

    One have to empty the recycle bin.

    This is not obvious and I want to suggest to put the not actively used tags in the recycle bin as well...

  • Petras Surna 90 posts 144 karma points
    Apr 14, 2021 @ 02:03
    Petras Surna
    1

    In Umbraco 8 I believe you need to run this SQL query

    delete from cmsTags where id not in (select tagId from cmsTagRelationship)
    

    I am trying to work out all queries you need to run to stop the database from growing at all if you add and then delete content and empty the recycle bin and came up with these three queries

    delete from umbracoLog
    delete from umbracoCacheInstruction
    delete from cmsTags where id not in (select tagId from cmsTagRelationship)
    

    There may be more, but this works for my test system.

  • Emma Garland 41 posts 123 karma points MVP 7x c-trib
    Dec 06, 2022 @ 15:03
    Emma Garland
    0

    Can confirm that in Umbraco 10, the query still works

    delete from cmsTags where id not in (select tagId from cmsTagRelationship)
    
Please Sign in or register to post replies

Write your reply to:

Draft