• I’ve written a simple plugin to add a couple of post types to my multisite installation. One of the post types has a meta field which contains a drop down list of posts from the other post type. However I’m getting the following error;

    Invalid argument supplied for foreach() in blaa\wp-includes\query.php on line 1702

    My code to populate the dropdown is as follows;

    $properties = get_posts( array( 'post_type' => 'property', 'posts_per_page' => -1 ) );
    $propertyList = array();
    
    if( $properties ) {
    	foreach( $properties as $property ) {
    		$propertyList[] = array(
    			'id' => $property->ID,
    			'name' => $property->post_title
    		);
    	}
    }

    I’ve been looking and trying to fix this for a couple of hours now but I’m beaten. Has anyone any suggestions?

Viewing 1 replies (of 1 total)
  • Thread Starter Chris

    (@chips)

    A quick update to this; I’ve noticed this error does not occur when I move the plugin code to the theme’s functions file. This error only occurs when the code is added as a plugin.

Viewing 1 replies (of 1 total)
  • The topic ‘Invalid argument supplied for foreach()’ is closed to new replies.