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

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




The taxonomy term was obviously not saved.

  • Can you add the code fragment that defines $args
    – anu
    Commented Mar 28, 2011 at 9:26
  • try setting the add_action priority like i did in my example. add_action( 'init', 'type_init', 0 );
    – Patriek
    Commented Mar 28, 2011 at 9:37
  • @Patriek: Just tried add_action( 'init', 'type_init', 0 ); without luck - error still showing.
    – Skymaiden
    Commented Mar 28, 2011 at 9:47
  • Would be a whole lot easier to debug your problem if you posted more of your code, ie. the post type and taxonomy registration code. Additionally it would also be helpful to also list the plugins that are active on the two installations.
    – t31os
    Commented Mar 28, 2011 at 12:02
  • Thanks @t31os. I did post the post type and taxonomy registration code (the word "code" in "Could this be because of an error in my register_post_type or register_taxonomy code?" is a link to pastebin). I only have the Shadowbox JS plugin on my local server, and the following ones on the live server (as in the comment response to Patriek): Google Analytics, Google Analytics Dashboard, Google XML Sitemaps, and WP Maintenance Mode. I seem to have eliminated the problem as I've written in my answer below, although to me it does seem to have just been a weird bug.
    – Skymaiden
    Commented Mar 28, 2011 at 15:57

4 Answers 4


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?


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 );
  • Hi, thanks for the response. I only uploaded my theme folder to the server, as there was already a running version using a different theme. Could this have caused conflicts? (It hasn't in the past for me, but this is my first time using custom post types and taxonomies.) You are correct in that args->taxonomy is non-existent - am I meant to define that myself in my functions.php file? Apologies for being slow to understand.
    – Skymaiden
    Commented Mar 28, 2011 at 9:39
  • the register post type says that the taxonomies var has to be an array. That could be the problem, you defined a string value.
    – Patriek
    Commented Mar 28, 2011 at 9:45
  • You register the args->taxonomy in your register post type. Its unlikely that a running theme will interfere, but just to make sure reactive your new them. There has to be a difference between your server and localhost.
    – Patriek
    Commented Mar 28, 2011 at 9:54
  • Oh sorry, I was looking in the wrong file (post.php) for args->taxonomy. I tried deactivating and reactivating my theme, but the warning persists. Maybe I should try removing the theme folder from the server completely and re-uploading a fresh copy?
    – Skymaiden
    Commented Mar 28, 2011 at 10:03
  • 1
    doesnt hurt to try, one question though are you using the same plugins on your dev machine as on the production server, your taxonomy name 'type'is a bit generic, it could be conflicting with other plugins.
    – Patriek
    Commented Mar 28, 2011 at 10:15

The variable $args, where does it come from? Perhaps you have register_globals_on on your local machine, but it's off on the server in the php.ini.


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. :-)

  • Somehow the warning came back this morning. I narrowed down the problem to the 'taxonomies' parameter in my custom post type registration. Commenting this out made the warning disappear. I then called register_taxonomy_for_object_type('sm_types', 'sm_portfolio'); directly, and everything seems to be in order again. I think the main cause of my problem was not namespacing my taxonomy. 'Type' is a reserved term. This was brought to my attention by Patriek in a comment so I can't mark it as the answer...
    – Skymaiden
    Commented Mar 29, 2011 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.