Support

Account

Home Forums Add-ons Flexible Content Field Add Flexible Content and fields to post

Helping

Add Flexible Content and fields to post

  • I am setting up default posts when my theme is installed. It creates the post and returns the id but I have been unsuccessful in inserting the ACF Flexible Content. They do not have any example code or information on inserting Flexible Content in their documentation. I have created the code below but have been unsuccessful in my attempts.

    	$config=array(
    		array(
    			"type" => "menu",
    			"subfields" => array(
    				'field_589ad3b3b6ccf'=>'menu', // wrapper_class
    				'field_589ad3b3b6cce'=>'menu', // wrapper_id
    				'field_589ad402b6cd1'=>'7', // menu_type
    				'field_59876063512cb'=>'left', // menu_alignment
    				'field_589ad3dcb6cd0'=>'2', // menu_selection
    				'field_589ad3b3b6ccd'=>'1' // menu_width
    			) 
    		)
    	);
    	foreach($config as $field){
    		// There is no documentation on how to add the element to the initial field
                    // I need to add menu to field_589ad3b3b6ccd
    
    		foreach ($field['subfields'] as $sub){
    			// I have tried
    			add_row( 'field_589ad3b3b6ccd', $sub, $headerID );
    			// I have tried
    			add_sub_row( 'field_589ad3b3b6ccd', $sub, $headerID );
    		}
    	}
  • Documentation should be here:

    https://www.advancedcustomfields.com/resources/add_sub_row/

    So, you need to know your flex-content fields’ field name too.

    For example, if your field_name is ‘page_blocks’, you’d do something like:

    
    foreach ($config as $index => $field) {
        foreach ($field['subfields'] as $key => $value) {
            add_sub_row(array('page_blocks', $index, $key), $value);
        }
    }
    

    p.s i haven’t tested yet.

    Cheers

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Add Flexible Content and fields to post’ is closed to new replies.