Hướng dẫn gắn taxonomy terms to nodes sử dụng Views Bulk Operations

Hướng dẫn gắn taxonomy terms to nodes sử dụng Views Bulk Operations

In this article I am going to show you a quick trick that will allow you to assign taxonomy terms to a lot of nodes all at once. For this we will use Views and Views Bulk Operations and will require no coding whatsoever. So let's begin.

First off, make sure you have the 2 modules installed. Drush will quickly take care of that for you if you don't have them yet:

drush dl ctools views vbo && drush en ctools views views_ui vbo

Now, the next thing we need to do is create a View page that displays the content (nodes, users, etc) you'd like to operate on in bulk (in our case, add taxonomy terms to). Make sure it uses fields and for start, the title field will be enough. For filtering, use whatever you need to filter the View to show only the content you want and sorting doesn't really matter.

Next up, add a new field of the type:Bulk operations: Content . This will provide next to the node title a checkbox for you to select that node to be part of the bulk operation.

To configure this field, make sure you check the boxes Modify entity values and Show available tokens followed by selecting the values of which field you'd like changed (in our case the taxonomy term reference field). In the screenshot below, you can see my selection for the Tags field of the Article node (I am going with a node view displaying articles).

Now you can save the View and navigate to its page. In the image below you can see my example. A table formatted view with the checkbox and the Article node title to its right. And the VBO operations above it.

How to batch assign taxonomy terms to nodes using Views Bulk Operations

Now, let's say I want to apply a taxonomy term to all these nodes. I can select them all (either manually or using the top-most checkbox dedicated for selecting all rows at once), choose my operation (Modify entity values) and click Execute. And this is then my next screen:

I have an autocomplete widget (like the default Article content type Tags field referencing taxonomy terms) where I can select one or more terms I'd like applied to all those nodes. I also have an option to ensure that existing values do not get overriden, by checking the respective checkbox. And lastly, I have some tokens available to use (because of the Tokens module).

Once I select my terms and press Next, I get an overview of how many nodes are going to be affected by this change (as you can see below). And that's basically it.

One thing to keep in mind here. If you are adding a non already existing taxonomy term, VBO will create that term as many times as the number of nodes being processed. So you'll end up with a bunch of terms with the same title. Probably not something you either expect or want. I therefore recommend you create your term before and then apply it to the content.

Hope this helps!

Bạn thấy bài viết này như thế nào?: 
Average: 5 (1 vote)
Ảnh của Khanh Hoang

Khanh Hoang - Kenn

Kenn is a user experience designer and front end developer who enjoys creating beautiful and usable web and mobile experiences.

Tìm kiếm bất động sản

 

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Bitcoin đang 'nóng' nhất kể từ ngày lên giá 20.000 USD

Theo Bloomberg Bitcoin đang 'nóng' nhất kể từ ngày lên giá 20.000 USD hồi tháng 12.2017

Theo Bloomberg, có một tín hiệu mà những người yêu tiền mã hóa nên chú ý: Bitcoin hiện ở mức đắt đỏ nhất kể từ trước ngày “bong bóng vỡ”, khi giá cả từ 20.000 USD lao dốc không phanh.

Gigan JSC - Number Talks & Number Works

Gigan JSC - Cách lấy hóa đơn từ quảng cáo Google, Facebook

Rất nhiều Startup Việt Nam và cả doanh nghiệp lớn gặp phải lúng túng trong việc hợp thức hóa chi phí quảng cáo Google và Facebook vào báo cáo tài chính cho doanh nghiệp.

Sử dụng panels page để làm trang Access Denied - 403

Sử dụng panels page để làm trang Access Denied - 403

What happens when a user bookmarks an access-protected page?

Công ty diệt chuột T&C

 

Diet con trung