ID, 'acf_field', true); $options = ' '; foreach($option_array as $option) { $new = $option->meta_key; $selected = ($old == $new) ? 'selected' : '' ; $options .= ''; } $form_fields["acf_field"]["html"] .= ""; $form_fields["acf_field"]["html"] .= "
"; return $form_fields; } add_filter("attachment_fields_to_edit", "acf_setup_select_field", null, 2); function acf_save_selected_cf($post, $attachment) { if( ($attachment['acf_field_text'] == '' ) ) { $val = $attachment['acf_field_select']; } else { $val = $attachment['acf_field_text']; } $old = get_post_meta($post['ID'],'acf_field',true); delete_post_meta($post['post_parent'], $old); update_post_meta($post['ID'], 'acf_field', $val, $old); update_post_meta($post['post_parent'], $val, $post['guid'], $old_val); return $post; } add_filter("attachment_fields_to_save",'acf_save_selected_cf',null,2); function acf_get_cfs() { global $wpdb; $pre = $wpdb->prefix; $q = "SELECT DISTINCT meta_key FROM wp_postmeta WHERE meta_key NOT LIKE '\_%'"; $result = $wpdb->get_results($q); return $result; } add_action('admin_print_scripts','acf_admin_script',10); function acf_admin_script() { $dir = WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__)); wp_register_script( 'acf-jq', $dir .'acf.js','jquery'); wp_enqueue_script('acf-jq'); } ?>