Tag nodes from a content type with a taxonomy term

Lets assume that you have a bunch of nodes for a content type and you want to tag them all with the same taxonomy term. First, find the term ID of the relevant term. In example, the term ID is 103 and the content type is "contact".

This is an example if an insert ... select statement.

  1. INSERT INTO term_node (nid, vid, tid)
  2. SELECT nid, vid, 103 as tid
  3. FROM `node`
  4. WHERE TYPE = 'contact'
  5. AND language = 'en'

If you liked this, you'll love my book, Master Drupal Module Development.

"..the must have drupal developers book"


Feeling stuck with Drupal 8 module dev?

Get the free 7 lesson course that will help you get started today without feeling overwhelmed.

  • Create Drupal modules with just a few commands using the Drupal Console
  • Create custom pages
  • Create custom blocks
  • Create admin forms
  • Demystify routers and controllers
  • Bonus material

Find out more


Comments

Hi, thanks for the good post,actually I am writing an application where I need to tag every alternate node type, I am stuck,can you give any input regarding this?acid reflux

Add new comment