The function content_taxonomy_terms_by_field currently returns all taxonomy terms for a given node regardless what $vid (vocabulary id) you send it. So, when content_taxonomy_field calls content_taxonomy_terms_by_field for each content taxonomy field you have defined on a page, each field will be filled with all taxonomy terms. This, I believe, is not the intended behavior.

To stop the entire taxonomy from printing for each content taxonomy field:

edit content_taxonomy.module
in function content_taxonomy_terms_by_field, around line 214,
replace:

    $result = db_query("SELECT n.tid FROM {term_hierarchy} h, {term_node} n WHERE
      n.nid = %d AND n.tid = h.tid AND h.parent = %d", $node->nid, $parent);

    while ($data = db_fetch_array($result)) {
      $term = taxonomy_get_term($data["tid"]);
      $additions[$term->tid] = $term;
    }
    return $additions;

with:

    $result = db_query(db_rewrite_sql('SELECT t.tid, t.* FROM {term_data} t 
      INNER JOIN {term_hierarchy} h ON t.tid = h.tid   
      INNER JOIN {term_node} r ON r.tid = t.tid 
      WHERE t.vid = %d AND r.nid = %d AND h.parent = %d  
      ORDER BY weight', 't', 'tid'), $vid, $node->nid, $parent);
    
    $terms = array();
    while ($term = db_fetch_object($result)) {
      $terms[$term->tid] = $term;
    }
    return $terms;
CommentFileSizeAuthor
#10 content_taxonomy.patch838 bytesDavid Lesieur

Comments

Axmodeux’s picture

I will follow this thread because, I think I meet the same problem.
I don't search enough to be sure that is not my fault ^^'

wojtha’s picture

I have had the same problem and this patch works for me.

Thanks dmarble!

dmarble’s picture

I was on the clock at work, so it was my pleasure!

leeksoup’s picture

Priority: Normal » Critical

Thanks dmarble!
I just updated to latest version for a fix to the critical bug reported at http://drupal.org/node/121242
But as soon as I did that and edited & saved a node, its CT fields would get hosed. Randomly populated with tids belonging to other vocabs, breaking my site. This fixes it.

CT owner, please roll this or equivalent patch into main codestream.

Anonymous’s picture

I have this problem too. The patch didn't work for me. I still see all terms in both displays.

ilmaestro’s picture

For what it's worth, I had this problem to and the patch worked. Hopefully it gets commited.

yeeloon’s picture

dmarble u rock!

i've been searching high n low for the solution, finally i came across your solution!

Yup, hopefully it gets committed.

pgrunzjr’s picture

dmarble,

Thank you very much for this. I knew something wasn't right but don't yet have knowledge enough of drupal's inner workings to fix it myself. Worked like a charm. Hope this gets committed.

Anonymous’s picture

Above patch solved my similar issues.

David Lesieur’s picture

StatusFileSize
new838 bytes

The attached patch shows how I solved it.

The field's vocabulary was never taken into account because the condition is_numeric($parent) in if (is_numeric($parent) && $depth == 1) was always true. When no term is specified for the field, $parent is zero... and zero is numeric. Thus, the else block was never visited in my case, and it is that block that selects terms within the field's designated vocabulary.

flndr’s picture

Neither the original suggestion or the patch submitted by David is working for me.

leeksoup’s picture

Latest version of CT does not have the original problem reported on this bug - at least it works for me.

blinko’s picture

I used the latest version of Drupal & CT but I had still this problem... So I applied the patch as described above and it solved the bug for me!... Thanks :-)

But why isn't that patch dated AUG 07, included in the latest version dated JAN 08... (?!)

fde’s picture

Was burned by the same bug today.
Good for me that I found this thread, after some hours trying to understand if I was doing something wrong...
The fix from dmarble solved the issue. Would be good to integrate it in the last development version.

summit’s picture

Subscribing, greetings, Martijn

bcn’s picture

Patch from #10 works for me... Thanks

csc4’s picture

The patch at http://drupal.org/node/210824 fixed this for me.

bjacob’s picture

For me patch supplied in #10 solved the problem. It's import to edit and submit the node again. Thanks a lot!

magnus’s picture

Status: Needs review » Closed (fixed)

Cleanup of old issues. According to maintainer: "active development is only done for the 6.x branch! 5.x is not supported any more".
Open a new issue if problem still exist.