WordPress.org

Ready to get started?Download WordPress

Forums

Need help resolving Warning: Invalid argument supplied for foreach() in /home/te (18 posts)

  1. galigul
    Member
    Posted 1 year ago #

    The complete error is:

    Warning: Invalid argument supplied for foreach() in /home/telapak5/public_html/wp-content/themes/smartstart/functions/custom-functions.php on line 337

    It's occurring on my homepage : http://www.telapakkarya.com

    lines 335
    $meta = wp_get_attachment_metadata( $id );
    lines 337
    foreach( $meta['sizes'] as $size => $values ) {
    lines 339
    if( $values['file'] == $file && $url == array_shift( wp_get_attachment_image_src( $id, $size ) ) ) {
    lines 340
    //$this->attachment_size = $size;
    lines 341
    return $id;

    If anyone know how to fix this error, I'd greatly appreciate learning how to fix it. Thanks everyone!

  2. Andrew
    Forum Moderator
    Posted 1 year ago #

    You can wrap the foreach loop with an if statement that checks whether condition is true before executing the loop.
    E.g

    if ( $meta['sizes'] ) {
     foreach ( $meta['sizes'] as $size => $values ) {
      ...
     }
    }
  3. prionkor
    Member
    Posted 1 year ago #

    Its is possible that their isn't anything returned from the wp_get_attachment_metadata() function or $meta['sizes'] is not exists or its not an array.

    Try this:

    $meta = wp_get_attachment_metadata( $id );
    
    if($meta && isset($meta['sizes'])){ // check for if we have anything in $meta['size']
    foreach( $meta['sizes'] as $size => $values ) {
        if( $values['file'] == $file && $url == array_shift(wp_get_attachment_image_src( $id, $size ) ) ) {
        //$this->attachment_size = $size;
        return $id;
        } // if ends
    } // foreach ends
    }
  4. galigul
    Member
    Posted 1 year ago #

    after I edit a message like this

    Parse error: syntax error, unexpected $end in /home/telapak5/public_html/wp-content/themes/smartstart/functions/custom-functions.php on line 1359

    line 1359
    add_action('ss_framework_custom_scripts', 'ss_framework_insert_sliders_scripts');

  5. Andrew
    Forum Moderator
    Posted 1 year ago #

    Make sure you've closed off the if statement's parenthesis.

  6. galigul
    Member
    Posted 1 year ago #

    This now appears

    Parse error: syntax error, unexpected T_IF in /home/telapak5/public_html/wp-content/themes/smartstart/functions/custom-functions.php on line 1359

    line 1359
    add_action if('ss_framework_custom_scripts', 'ss_framework_insert_sliders_scripts');

  7. prionkor
    Member
    Posted 1 year ago #

    Try using a code editor to edit the file. Most of the code editor will tell you if you have a syntax error. What editor are you using?

  8. Andrew
    Forum Moderator
    Posted 1 year ago #

    What's the line before the if statement and can you post your if statement?

  9. galigul
    Member
    Posted 1 year ago #

    the line before the if statement

    [ Moderator Note: Please post code or markup snippets between backticks or use the code button. As it stands, your code may now have been permanently damaged/corrupted by the forum's parser. ]

    if ( !function_exists('ss_framework_insert_sliders') ) {
    
    	function ss_framework_insert_sliders_scripts() {
    
    		global $wpdb;
    
    		$query = "SELECT post_id
    				  FROM $wpdb->postmeta
    				  WHERE meta_key = 'ss_slider_slides'";
    
    		$sliders = $wpdb->get_results( $query );
    
    		foreach ( $sliders as $slider ):
    
    			$post_obj = get_post( $slider->post_id );
    
    			// Check that slider actually exist, so we don't insert unnecessary code
    			if( !ss_framework_has_shortcode('slider') && get_post_type() != 'slider' )
    				continue;
    
    		?>
    
    <script>
    
    (function( $ ) {
    
    	var $slider = $('#<?php echo $post_obj->post_name; ?>');
    
    	if( $slider.length ) {
    
    		// Prevent multiple initialization
    		if( $slider.data('init') === true )
    			return false;
    
    		$slider.data( 'init', true )
    			   .smartStartSlider({
    				   width              : <?php echo ss_framework_get_custom_field('ss_slider_width', $slider->post_id ); ?>,
    				   height             : <?php echo ss_framework_get_custom_field('ss_slider_height', $slider->post_id ); ?>,
    				   contentSpeed       : <?php echo ss_framework_get_custom_field('ss_slider_content_speed', $slider->post_id ); ?>,
    				   showContentOnhover : <?php echo ss_framework_get_custom_field('ss_slider_show_content_onhover', $slider->post_id ); ?>,
    				   hideContent        : <?php echo ss_framework_get_custom_field('ss_slider_hide_content', $slider->post_id ); ?>,
    				   contentPosition    : "<?php echo ss_framework_get_custom_field('ss_slider_content_position', $slider->post_id ); ?>",
    				   timeout            : <?php echo ss_framework_get_custom_field('ss_slider_autoplay', $slider->post_id ); ?>,
    				   pause              : <?php echo ss_framework_get_custom_field('ss_slider_stop_on_click', $slider->post_id ); ?>,
    				   pauseOnHover       : <?php echo ss_framework_get_custom_field('ss_slider_pause_on_hover', $slider->post_id ); ?>,
    				   type               : {
    					   mode           : "<?php echo ss_framework_get_custom_field('ss_slider_transition', $slider->post_id ); ?>",
    					   speed          : <?php echo ss_framework_get_custom_field('ss_slider_speed', $slider->post_id ); ?>,
    					   easing         : "<?php echo ss_framework_get_custom_field('ss_slider_easing', $slider->post_id ); ?>",
    					   seqfactor      : <?php echo ss_framework_get_custom_field('ss_slider_seq_factor', $slider->post_id ); ?>
    				   }
    			   });
    
    		// Detect swipe gestures support
    		if( Modernizr.touch ) {
    
    			function swipeFunc( e, dir ) {
    
    				var $slider = $( e.currentTarget );
    
    				if( dir === 'left' ) {
    					$slider.find('.pagination-container .next').trigger('click');
    				}
    
    				if( dir === 'right' ) {
    					$slider.find('.pagination-container .prev').trigger('click');
    				}
    
    			}
    
    			$slider.swipe({
    				swipeLeft       : swipeFunc,
    				swipeRight      : swipeFunc,
    				allowPageScroll : 'auto'
    			});
    
    		}
    
    	}
    
    })( jQuery );
    
    </script>
    
    		<?php
    
    		endforeach;
    
    	}
    
    }
    add_action if ('ss_framework_custom_scripts', 'ss_framework_insert_sliders_scripts');
  10. galigul
    Member
    Posted 1 year ago #

    some of my other portfolio such problems do not occur

  11. Andrew
    Forum Moderator
    Posted 1 year ago #

    Just the one line before the if statement suggested from forum volunteers of this thread and the one line of the if statement, please.

  12. galigul
    Member
    Posted 1 year ago #

    sorry, I do not understand the point? can be explained

  13. Andrew
    Forum Moderator
    Posted 1 year ago #

    I'm trying to find the original the line with your parse error.

  14. galigul
    Member
    Posted 1 year ago #

    maybe you can visit my website and check out the portfolio section click PPSD 28 it should be next and previous mark like the others.

    http://www.telapakkarya.com

    thank you

  15. Andrew
    Forum Moderator
    Posted 1 year ago #

    What is supposed to happen when I visit that link?
    I get a never-ending loading .gif.

  16. LeandroRC
    Member
    Posted 1 year ago #

    I have a similar problem. =(

    Warning: array_count_values() [function.array-count-values]: Can only count STRING and INTEGER values! in /home/leandror/public_html/wp-content/themes/smartstart/functions/custom-functions.php on line 633

    [ 1,777 lines of code moderated, that's just way too much. For that many lines of code please use pastebin.com instead. ]

  17. @LeandroRC Please start your own topic. Despite similarity this one probably does not have anything to do with your own.

    http://wordpress.org/support/forum/how-to-and-troubleshooting#postform

    If you do post your own topic, do not post 1,777 lines of code here. Use http://pastebin.com/ instead if you must.

  18. whoopys
    Member
    Posted 1 year ago #

    The problem is "inside" the smarstart theme I suppose

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags