Hi,
(Title has been renamed. See first reply message below for an update to this problem.)

The Problem

Recently upgraded from Drupal 5.2 up to Drupal 6.14.
Every time I manually run cron from the Status Report area, I get this error message

warning: Invalid argument supplied for foreach() in /home/(home directory*)/public_html/(site directory*) /modules/taxonomy/taxonomy.module on line 1214.

(*My website info changed)

Anyone have any ideas about how to track down the problem?

The Website Environment

Here is a description of our website environment. Although there are several hundred pages in the website, I've never done much with taxonomy. Several years ago I did set up the following Vocabularies:

The Vocabularies

Here are the vocabularies (and the node types that they are attached to) in our website. (There are only attached to a handful of nodes)
Name...........................Type
Forums..........................Forum topic
Furniture Upholstery*........Blog entry, Book page, Forum topic, Page, Story
Image Galleries (not attached to anything)

* has some child terms attached to it.

History

Partly because I never understood the function or the importance of cron, and partly because I didn't know how to set cron to run automatically, I have never set up cron to run automatically in Drupal and have rarely run cron manually. So, I don't know where my database picked up this error.

The Code

Just for the record, here is a copy the code (that the error is pointing to) in the Taxonomy module as shown in the code editor at and around line 1214:

1209| /**
1210|  * Implementation of hook_nodeapi('update_index').
1211|  */
1212| function taxonomy_node_update_index(&$node) {
1213|   $output = array();
1214|   foreach ($node->taxonomy as $term) {
1215|     $output[] = $term->name;
1216|   }
1217|   if (count($output)) {
1218|     return '<strong>('. implode(', ', $output) .')</strong>';
1219|   }
1220| }

Taxonomy Information

Here are some links to information about Drupal Taxonomy:

  1. Here is a description of Taxonomy: Taxonomy: A way to organize content

Looking for a Solution

I have been (and continue to) search Drupal.org and the Internet for answers. Here are some of the messages that I have found:

  1. I saw aharown07's Project message vBulletin to Drupal "Invalid argument supplied for foreach() ... taxonomy.module on line 1214", but I have never used vBulletin and didn't see anything in the messages that seemed relevant to me.
    http://drupal.org/user/278693
  2. The above message had a link to this message: Invalid argument supplied for foreach() in taxonomy.module on line 1188 There are a lot of messages here. There might be something of value here, but so far haven't found anything useful.
  3. I also saw aharown07's message "Taxonomy won't index after migration... invalid foreach in taxonomy.module line 1214", but also didn't see anything that seem useful.

Other Articles That May Be Of Help:

Below I want to collect some links to other articles that might help to shed some light on how to track down a solution to this problem. I haven't yet found any helpful information to track this down, and I don't understand the programing of taxonomy to figure this out yet. So I want to add links to information that might help to figure this out. Here are a list of websites where the content of line 1214 is used in possibly a number of different ways.

  1. Display taxonomy terms broken out by vocabulary This article contains a discussion of the use of the terms in line 1214: "foreach ($node->taxonomy as $term) {"
  2. Displaying taxonomy as part of the content This article uses the content of our line 1214 in another way. Perhaps examining how it is used here might help to understand a little more?
  3. A Google search on "foreach ($node->taxonomy as $term) {" This is the list of results from the Google Search. Still need to investigate them further.

Comments

Stephen Winters’s picture

After reading about how someone else disabled some modules to track down an error message, I disabled ALL the modules, including ALL of the core modules. I then reran cron and there were NO error messages. So I began enabling the modules a few at a time, and then reran cron after each few had been enabled. So I tracked down that the Search module is causing the error message. Whenever I have the search module enable my website has the "warning: Invalid argument supplied for foreach() in /home/(home directory*)/public_html/(site directory*) /modules/taxonomy/taxonomy.module on line 1214." error message.
So, for the time being, I'm leaving the Search module disabled until I find out what to do from here. Does anyone know how to fix the problem caused by the search module? (see original message in this thread for more details.)

Best Wishes,
Stephen

crozilla’s picture

Disable Search module, then uninstall the module, then re-install the module. Worked for me.

geerlingguy’s picture

I can confirm that this fixed the issue for me, as well. Disable search.module, then go to the uninstall tab, then uninstall it, then go back to the list and re-enable it. [Edit: Worked for a while, but back to the error messages :(]

__________________
Personal site: www.jeffgeerling.com

shima’s picture

By disable search module problem would solved but enable search module return warning again :(
another problem is that I have several users and when I login to website with my admin user after minutes automatically change to another user that I never used!!!!
this means my admin user log out automatically and another user that I never didn't login, in my browser automatically login
important modules that i used is:
1. quiz
2. webfm
3. view & CCK
4. Subuser
5. Content Profile
I have windows hosting for my site

greenmachine’s picture

I've got this issue too. Disabling and uninstalling the search issue did not solve it. Checking for nid/vid problems in the node/node_revisions table didn't yield anything either (as suggested http://drupal.org/node/310164).

Last thing I did was install the twitter module, but not sure why that would do anything (and I subsequently disabled it).

This is what the $node object being passed to that taxonomy function looks like:

stdClass Object
(
    [build_mode] => 2
    [body] => 
    [readmore] => 
    [content] => Array
        (
            [body] => Array
                (
                    [#weight] => 0
                    [#value] => 
                    [#title] => 
                    [#description] => 
                    [#printed] => 1
                )

            [#title] => 
            [#description] => 
            [#printed] => 1
        )

)

Seems like a malformed or underformed node object; obviously there is no taxonomy attribute that can be iterated in a foreach, hence the error/warning.

grguth’s picture

I've run across the same issue, the node with no taxonomy. The only thing I've found in my database is a node type which no longer exists. I have three nodes of a type which were loaded by a module I later uninstalled. They also have no language code. I wonder if cron is hitting these nodes, finding no module to format the node object, so just building an incomplete proto node, and then handing it off to taxonomy which drops dead on the foreach(). Oddly enough, further up in taxonomy, there is a bit of code which checks for the node->taxonomy and doesn't execute the foreach() if the value is empty.