Title: [Plugin: Media Custom Fields] no custom fields breaks foreach loop.
Last modified: August 20, 2016

---

# [Plugin: Media Custom Fields] no custom fields breaks foreach loop.

 *  [maxemil](https://wordpress.org/support/users/maxemil/)
 * (@maxemil)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/plugin-media-custom-fields-no-custom-fields-breaks-foreach-loop/)
 * Minor fix, if you havent made any custom fields yet, the foreeach in line 233
   will complain.
 * media-custom-fields.php
 * Inserting an “if ($tqmcf)” (check that the variable isent empty):
 *     ```
       function tqmcf_edit( $form_fields, $post ) {
       		$tqmcf = get_tqmcf();
   
               if ($tqmcf) // new
               { // new
       		  foreach ( $tqmcf as $field )
                 {
       			$form_fields[$field["slug"]]['label'] = $field['name'];
       			$form_fields[$field["slug"]]['value'] = get_post_meta( $post->ID, $field["slug"], true );
       			$form_fields[$field["slug"]]['helps'] = $field['description'];
       		  }
               }  // new
                 return $form_fields;
           }
       ```
   
 * very usefull plugin :thumbs-up:
 * [http://wordpress.org/extend/plugins/media-custom-fields/](http://wordpress.org/extend/plugins/media-custom-fields/)

Viewing 1 replies (of 1 total)

 *  Thread Starter [maxemil](https://wordpress.org/support/users/maxemil/)
 * (@maxemil)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/plugin-media-custom-fields-no-custom-fields-breaks-foreach-loop/#post-2104869)
 * Also the same loop issue when in the admin line 101
 * admin/administration_page.php
 *     ```
       if ($tqmcf)  // not empty  // new
                   { // new
         			  $fields = array();
                     foreach($tqmcf as $field) {
       				$fields[] = $field["slug"];
       			  }
   
       			$fields = "'".implode("', '", $fields)."'";
       			$items = $wpdb->get_col("SELECT DISTINCT(meta_key) FROM $wpdb->postmeta WHERE meta_key LIKE '%tqmcf_%' AND
       				meta_key NOT IN ($fields)
       			");
                   }  // new
       ```
   
 * again, this is a nice plugin 🙂

Viewing 1 replies (of 1 total)

The topic ‘[Plugin: Media Custom Fields] no custom fields breaks foreach loop.’ 
is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/media-custom-fields.svg)
 * [Media Custom Fields](https://wordpress.org/plugins/media-custom-fields/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/media-custom-fields/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/media-custom-fields/)
 * [Active Topics](https://wordpress.org/support/plugin/media-custom-fields/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/media-custom-fields/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/media-custom-fields/reviews/)

 * 1 reply
 * 1 participant
 * Last reply from: [maxemil](https://wordpress.org/support/users/maxemil/)
 * Last activity: [14 years, 12 months ago](https://wordpress.org/support/topic/plugin-media-custom-fields-no-custom-fields-breaks-foreach-loop/#post-2104869)
 * Status: not resolved