Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Support

Deleting certain tags from all pages

admin

Solved by pamtbaau View solution

Started by Kyle Alexander Buan 6 years ago · 2 replies · 628 views
6 years ago

We have a fairly large website with multiple posts, and we would like to remove a certain tag (let's just call it "tag A") from all pages.

For a small amount of pages, we could just do this manually but if there are multiple tags to delete, or the page amount is large, it would become tedious easily.

Can anyone please guide me to do this simpler (for example, using a built-in Admin feature, or using an existing plugin), or if possible, point me to the right direction on how to make this plugin? (Doesn't have to be in code, just general pointers!)

Thanks a lot in advance!

6 years ago Solution

@orthocube, Using a plugin you could try something like:

  • Install devtools if not already: $ bin/gpm install devtools
  • Create new plugin: $ bin/plugin devtools newplugin
  • Create function handling event onPagesInitialized
    • Create a collection based on taxonomy (see example in docs)
    • Loop through pages found
    • Get taxonomy: $tax = $page->taxonomy(); (see Page class)
    • Remove the tag from the array
    • Set taxonomy: $page->taxonomy($tax);
    • Save page: $page->save();
👍 1
last edited 07/30/20 by pamtbaau
6 years ago

This is exactly the guide I've been looking for! I can write code, so it's just the general guideline I needed.

Thank you very much!

It would be awesome if the plugin can be viewed from the Admin page and triggered using buttons and input textboxes, so I'll try my best to find out how to do that.

Thanks again!

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
2 53 9 hours ago
Support · by Anna, 3 days ago
2 59 12 hours ago
Support · by Justin Young, 13 hours ago
1 30 13 hours ago
Support · by Duc , 1 week ago
2 65 5 days ago
Support · by Colin Hume, 1 week ago
2 56 5 days ago