Support

Account

Home Forums Add-ons Flexible Content Field Dynamic titles for flexible content pane

Helping

Dynamic titles for flexible content pane

  • Hi,

    I tried following this : https://support.advancedcustomfields.com/forums/topic/dynamic-title-for-flexible-content-pane/

    For some reason, although it looks ok, when you click on the flexible content field it overwrites and deletes the title in there. I can’t figure out why.

    Has anyone had this/ can figure out why the title disappears (the whole element disappears from the html!)

    Thank you

    The function:

    
    add_filter('acf/fields/flexible_content/layout_title/name=desktop_menu', 'my_acf_fields_flexible_content_layout_title', 10, 4);
    function my_acf_fields_flexible_content_layout_title( $title, $field, $layout, $i ) {
    $rows = get_sub_field('menu_items');
    	  $ret = $title;
    		if ($custom_title = get_sub_field('menu_items')[0]["link_to"]) {
    			$ret = $custom_title;
    		}
    	
    	$custom_title = $title;
    
        return $ret;
    }
    

    Acf structure:

    Flexible content field ‘desktop_menu’, layout below that ‘level_one_links’, level below that ‘menu_items’ repeater, level below that is ‘link_to’ which is a text field

  • It looks like you have nested repeater fields. You need to use nested have_rows() Loops, or you need to access the nested value in the array from your get_sub_field() call.

    
    $rows[0]['level_one_links'][0]['menu_items'][0]['link_to']
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.