What is causing this error? “Warning: Invalid argument”

I need urgent help figuring this out please – I’ve been working on a WordPress theme locally without problems, and now that I’ve uploaded it to the live server I’m getting this error:

Warning: Invalid argument supplied for foreach() in
/homepages/42/d357924500/htdocs/wp-includes/post.php
on line 1011

Read More

The corresponding code is related to the register_post_type function:

foreach ( $args->taxonomies as $taxonomy ) {
        register_taxonomy_for_object_type( $taxonomy, $post_type );
    }

Could this be because of an error in my register_post_type or register_taxonomy code? The error shows both on the front-end and the admin side (also displays in widget option boxes when I try to update widgets – the changes don’t save).

I don’t really know much about PHP yet (still learning), but I know just enough to manage a few WordPress customisations. Both WordPress installations use version 3.1. Any help on this issue is very appreciated.

— UPDATE —

I tried creating a new term for my custom taxonomy of “type”, and I got this error in a red error box:

**Warning: Invalid argument supplied for foreach() in
/homepages/42/d357924500/htdocs/wp-includes/post.php
on line 1011

Warning: Cannot modify header information – headers already sent by
(output started at
/homepages/42/d357924500/htdocs/wp-includes/post.php:1011)
in
/homepages/42/d357924500/htdocs/wp-includes/class-wp-ajax-response.php
on line 129

Administration

administration0]]>Administration

administration0]]>**

The taxonomy term was obviously not saved.

Related posts

Leave a Reply

4 comments

  1. Ran into the same issue. @Patriek is correct. The ‘taxonomies’ argument must be an array, hence the plural. E.g.

    $args = array( 'taxonomies' => array( 'myTaxonomy' ) );

    This corrects the error.

    I only noticed this when moving a site to another server which leads me to think the register_post_type() function requires some php settings not enabled on the remote host. register_globals is enabled… any ideas what make this issue server dependent?

  2. My assumption would be that your args->taxonomy is empty, invalid or non-existent. without more code its hard to say why. Did you upload all the code from your localhost to the production server.

    Also sometimes this happens because the taxonomy is created after the register_post_type, but then the localhost code would give the same error. I usually call taxonomes like this.

    function initialize_taxonomy() {
        register_taxonomy( 'tax_name', 'tax_object', array(
                            'hierarchical' => false,
                            'query_var' => false,
                            'rewrite' => true,
                            'public' => true,
                            'show_ui' => true,
                    ) );  
    }
    add_action( 'init', 'initialize_taxonomy', 0 );
    
  3. So the error was being caused by my custom taxonomy registration. I managed to make the warning go away by cutting it out completely. On seeing that this seemed to fix the problem, I did a new register_taxonomy (using almost exactly the same code, but with the name changed as suggested by Patriek), and the warning has not come back.

    A big thanks to those who tried to help me. 🙂