Invalid argument supplied for foreach
means that the X in foreach X as ...
is not an array. You can prevent this error by type casting; add (array)
before the argument in the foreach statement. This will turn your variable into an array, essentially. In your code, the change would be…
foreach ( (array) $attach_meta['sizes'] as $size => $value ) {
Now keep in mind that this won’t fix the real issue here, which is that your code is expecting $attach_meta['sizes']
to be an array and it is not. You may want to refactor your code to handle that scenario.
Related Posts:
- Convert all uploaded PNG files to PNG-8 format
- How to make a image-size selected by default in Media upload – WP v3.5
- How do I change/modify the_post_thumbnail(); html output?
- Remove “Insert from URL” link in Media upload – WP 3.5
- How to add a class to the attachment images
- Adding a custom image upload size and making it selected by default?
- Set media upload attachment link to none and hide it in WP v3.5
- How to draw media details for Isotope gallery using Photoswipe
- Hide old attachments from wp media library
- How to register images uploaded via FTP in media library?
- How to upload imagick resource to media in wordpress
- How do I get images (with a thumbnail preview) to show in search results?
- Using wp_get_image_editor in a standalone script
- Change logo based on incoming domain
- Convert all images to PNG on file upload
- How to get media objects
- How to get specific image in media library with php
- Set the background to a default image if there isn’t a specified “featured image”
- How to control WordPress image metadata (using Imagick)?
- What is the alternative to “ when it comes to calling Media (image) files in the ‘attachment.php’ file?
- Scrape external webpage for first image and add it to new post
- WordPress automatically adds links to uploaded images
- Get featured image with custom size outside WordPress
- Else/If Statement to Display Photo Descriptions
- Image rotation issue (horizontal picture uploading as vertical) — Exif issue?
- Adding a ‘style=’ bit to image_send_to_editor output
- Hide media for non logged in users
- Retrieve alt text by referencing the img src
- not outputting medium size image URL
- How to use data URL in WordPress?
- How do I get the featured post to share on Social Media and show on Individual Post pages?
- Retrieving specific images from Media Library
- How do I routinely extract the thumbnail of the most recent post?
- Extend the WP_Customize_Image_Control class to change its non-frame $button_labels
- My customizer’s setting doesn’t set to the default and needed to click the control’s “Default” button before it’ll be set
- Save the outputted image into the Media Library, with a different filename and extension
- add if statement to the featured image
- An automatic way to crop images of different sizes
- How to automatically convert images to WebP on WordPress?
- Remove default Image Sizes
- Understanding responsive imagery
- WooCommerce: write featured image dimensions to custom fields in product’
- Generate and upload screenshot as featured image for user-submitted post
- Image alt tag is showing post title instead of Alt Text
- get current product name in functions.php
- Get first URL from post content
- Setting custom canonical urls
- Handling Body class based on Template
- Trigger popup in a php if/else statement
- Setting a cookie upon specific URL visit
- Get_avatar filter?
- Can’t get page content in WordPress
- WordPress child theme fails to override parent navigation menu in /inc/structure/header.php
- Way to querry data (tags) from a wordpress database?
- get post based on category chosen in drop down – The ajax method
- Adding Default Settings to Theme My Login plugin
- Image as Sales Badge
- how to make separate field in wordpress user_data_
- Function not working at one place
- jQuery not defined
- Displaying the Month and Year that a page was Created?
- Changing custom logo link
- Add a class to the anchor tag on HTML5 gallery
- How do you use WP slugs for PDF files / media?
- Conditional Header in wordpress
- Remove meta description on certain pages
- add_image_size for header_image
- Menu — How to add “current-menu-grand-ancestor” css class
- Use menu link or onClick to set a variable
- Swapping wp_dropdown_categories function with wp_category_checklist
- functions.php is being included twice, creating PHP fatal errors
- Add custom url to featured image
- Hide Hamburger Menu On Specific Page (Front Page/Home Page)
- Automatically remove a canceled order in Woocommerce
- Get image’s size name from it’s dimension
- Display fields as values in array from external SQL DB
- Only Show Link If div Exists
- Cannot display or echo alt text on featured image
- How to put a variable in a instance in the widget
- Create another “Display Site Title and Tagline” checkbox, “Header Text Color” setting and control
- Trying to establish connection to External Database
- Recent posts with featured image or fallback image with permalink
- add_action shortcut?
- Passing the custom field values in the wp_get_current_user array function
- Best practice for migration friendly images in posts/pages?
- Using fwrite() and “a” appends multiple times instead of once
- How to output a PHP file values by shortcode?
- Showing content from one page on another
- How to style options page in dashboard?
- How to insert a single row to WP database table?
- Get date numerical and separate?
- Where in PHP do I move title and meta (date) to bottom of each blog section?
- WSoD being caused by this piece of code
- Converting HTML Template to WordPress Theme
- How to Arrange PHP Files to Allow for Multiple Types of Pages?
- Add a variable in functions.php and call it in single.php
- How to access global variable $menu inside a class function
- Calling directories to load in wordpress
- WordPress add post format support not working
- Can I prevent the user from adding more than two levels deep of terms inside of a taxonomy metabox?