Support

Account

Home Forums Backend Issues (wp-admin) Multiple choice with dynamically loaded options disappears after save

Unread

Multiple choice with dynamically loaded options disappears after save

  • Hi!

    I’m using a multiple choice field in an “options page” to filter to handle which flexible layouts should and which should not appear in a flexible field.

    Before save, the multiple choice field is correctly populated.

    After save, the multiple choice field is not displayed at all.

    Removing from wp_options the row containing the field id – key correlation (_options_disabled_stripe_boxes > field_5c7e7d9938e86) makes the field appear again, and selected boxes reflect the previously saved value.

    Both before and after save layouts filtering appears to be correctly working.

    WP 5.1.1
    ACF Pro 5.7.13

    Finally, here’s the code.

    /** Populate avalaible stripe field options for the Developer Settings  */
    add_filter('acf/load_field/key=field_5c7e7d9938e86', 'qtheme_acf_stripe_flexible_boxes_filter');
    
    if (!function_exists('qtheme_acf_stripe_flexible_boxes_filter')) {
    	function qtheme_acf_stripe_flexible_boxes_filter($field) {
    		$is_admin = is_admin();
    
    		$screen = null;
    
    		if( $is_admin )
    		{
    			$screen = get_current_screen();
    		}
    
    		if( $screen !== null && ('qtheme_page_acf-options-developer' == $screen->id) )
    		{
    			$flexibleField = get_field_object('field_5b16bb7c19451');
    
    			$choices = array();
    
    			foreach( $flexibleField['layouts'] as $id => $settings )
    			{
    				$choices[$id] = $settings['label'];
    			}
    
    			$field['choices'] = $choices;
    		}
    
    		return $field;
    	}
    }
    
    /** Suppress unwanted stripe flexible boxes layouts */
    add_filter('acf/load_field/key=field_5b16bb7c19451', 'qtheme_acf_stripe_flexible_boxes_handler');
    
    if (!function_exists('qtheme_acf_stripe_flexible_boxes_handler')) {
    	function qtheme_acf_stripe_flexible_boxes_handler($field) {
    		$is_admin = is_admin();
    
    		$screen = null;
    
    		if( $is_admin )
    		{
    			$screen = get_current_screen();
    		}
    
    		if( $screen !== null && ('page' == $screen->id || 'qtheme_page_acf-options-developer' == $screen->id) )
    		{
    			if( 'page' == $screen->id )
    			{
    				$flexibleFieldFilter = get_field('disabled_stripe_boxes', 'option');
    
    				foreach( $flexibleFieldFilter as $flexibleFieldID )
    				{
    					unset($field['layouts'][$flexibleFieldID]);
    				}
    			}
    		}
    
    		return $field;
    	}
    }
Viewing 1 post (of 1 total)

The topic ‘Multiple choice with dynamically loaded options disappears after save’ is closed to new replies.