• Seeing a warning here…

    PHP Warning: Invalid argument supplied for foreach() in /embedded/includes/fields-post.php on line 660

    Similar to how you fixed this issue, I can resolve the warning as follows…

    if ( is_array( $_field_value ) && !empty( $_field_value ) ) {
    
    	foreach ( $_field_value as $_k => $_val ) {
    		// Check if valid
    		$validation = wptoolset_form_validate_field( 'post', $config, $_val );
    		$conditional = wptoolset_form_conditional_check( $config );
    		$not_valid = is_wp_error( $validation ) || !$conditional;
    		if ($add_error_message && is_wp_error( $validation )) {
    			$errors = true;
    			$_errors = $validation->get_error_data();
    			$_msg = sprintf( __( 'Field "%s" not updated:', 'wpcf' ), $field['name'] );
    			wpcf_admin_message_store( $_msg . ' ' . implode( ', ', $_errors ), 'error' );
    		}
    		if ( $not_valid ) {
    			if ( types_is_repetitive( $field ) ) {
    				unset( $field_value[$_k] );
    			} else {
    				break;
    			}
    		}
    	}
    
    }

    https://wordpress.org/plugins/types/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Beda

    (@bedas)

    That Post is very old and using old WordPress and Types versions.

    I do not see the error on my Localhost with the latest Types and WordPress versions.

    can you elaborate how I can reproduce this, so to inform the Developers in case?

    Thank you for your collaboration

    Thread Starter toddlevy

    (@toddlevy)

    It’s WP v4.4.2 and Types v1.8.11.

    I did not have the liberty to trace this up the chain and try to determine the cause, but this warning was in the logs and there is a foreach loop of $_field_value which it seems is sometimes not set as an array when it gets to that line (just like in the other ticket I referenced).

    Note that this is a very large site (~2 million posts, and more meta) and there are other things that break unexpectedly* — so it’s conceivable there’s a query upstream in the plugin that’s choking and preventing $_field_value from getting properly set.

    Hope this is helpful info.

    * e.g. things that just try to query on an imploded comma list of IDs can end up being too many characters for MySQL when there are a large number of items involved. For example, when the update_term_meta_cache gets called inside of get_terms that’s called on line 499 / 500 of /types/includes/fields-form.php, the query often fails so we end up having to do “hacks” like this…

    BEFORE
    $terms = apply_filters( ‘wpcf_group_form_filter_terms’, get_terms( $category_slug, array(‘hide_empty’ => false) ) );

    AFTER
    $terms = apply_filters( ‘wpcf_group_form_filter_terms’, get_terms( $category_slug, array(‘hide_empty’ => false, ‘update_term_meta_cache’ => false) ) );

    Thread Starter toddlevy

    (@toddlevy)

    EDIT: Just realized you’re saying the post I linked to is old. I see that, but the age of that post isn’t really relevant.

    Plugin Support Beda

    (@bedas)

    This situation is not replicable locally.

    WordPress and Types work great together without any warnings or errors at the current state of things.

    Being this a very large site, we need to analyze this.

    Please can you (if this issue is replicable with Types + WordPress and a default Theme) head over to our Types Forum, where we can exchange Login Data and eventual Site Snapshots?

    You can register for the Support forum here.

    If this issue is replicable we will include a fix in our next release, but I can not produce the warning on our Localhosts at the moment.

    Thank you for the cooperation and I apologize that I can not provide a fix here.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘nvalid argument supplied for foreach() in /embedded/includes/fields-post.php 660’ is closed to new replies.