1

Is it possible with Rules to set the numeric weight value of a taxonomy term as a CCK field when a node is saved?

I have 2 taxonomy vocabularies, and all nodes of a certain content type will have 1 term from each vocabulary. When not on the term's page, I need the sort order of nodes in a View to be by the term's weight. I therefore need to access the term's weight as a CCK field, so Views can use the value as a sort order. Can this be done with Rules?

apaderno
  • 28,547
  • 16
  • 75
  • 90
Evanss
  • 23,390
  • 94
  • 282
  • 505

1 Answers1

0
  1. You don't need to save the term weights in the node. In the view-sort option select term-weight from Taxonomy. or you can also select the row style as table and then select the field, taxonomy-terms all(you can filter by vocabulary also) from the taxonomy group and then sort the table based on that field.
  2. If you really want to save the terms, then you don't necessarily need Rules for that and content-taxonomy might do the trick for you. And then you can sort your view by that field.

EDIT : 2 . Add a custom-php-field in the views and write something like

return taxonomy_term_load($my_tid)->weight; And then sort the view by this field.

Gokul N K
  • 2,428
  • 2
  • 32
  • 40
  • 1. When on the page of a term from vocabulary B, I need to sort by terms for vocabulary A. The taxonomy weight sort criteria doesn't let you specify a vocabulary so I cant use it for this. – Evanss Apr 11 '11 at 13:19
  • The table solution should work for me but its not ideal for my layout. I also try to avoid tables for accessibility and standards compliance, but I guess this data is sort of relevant to a table format. Thanks – Evanss Apr 11 '11 at 13:22
  • Ill have a look at content taxonomy. Thanks – Evanss Apr 11 '11 at 13:26
  • Im using Content Taxonomy but all it can relieve to views is the term names, not their weight. Thanks – Evanss Apr 12 '11 at 10:59
  • Oops didn't know this. Then you need to have a custom-field in views which will get the weight of the term. – Gokul N K Apr 12 '11 at 11:10
  • Do you mean the Views Custom Field module? Presumably I would use the PHP code feature? How can I go about finding out what PHP to write? – Evanss Apr 12 '11 at 11:13
  • Thanks for your code. Don't I have to specify a vocabulary ID though so the code uses the correct vocabulary? – Evanss Apr 17 '11 at 16:51
  • tid is a unique number and hence can only belong to one vocabulary. However the code I have gives just suggestive, not the exact code, check out the docs for more – Gokul N K Apr 17 '11 at 18:09