This topic contains 2 replies, has 2 voices, and was last updated by  Steve 4 years ago.

  • Author
    Posts
  • #5719

    pwwwpwww
    Participant

    In the latest beta version of Piklist there’s an awesome new demo in the 2-level addmore section called Page Modules – basically ACF Flexible Content lite 😉

    I’ve tried using the code found in the addmore docs but can’t seem to make it work. I then spied Steve’s advice in this thread – supposedly the latest version of Piklist doesn’t require the creation of template parts for repeatable fields any more. Unfortunately the code example he posted doesn’t work on nested repeater fields like those in the Page Modules demo.

    Does anyone know how to output this type of nested add_more? Extra hugs to anyone who can share a code example that someone without php knowledge might understand 🙂

    Here’s an abridged version of the field group I’m rattling on about:

    <?php
    /*
    Title: Page builder
    Post Type: page
    */
    
    // Taken from the Piklist addons demo. Would be awesome as a page builder / alternative to ACF flexible content field.
    
      piklist('field', array(
        'type' => 'group'
        ,'field' => 'module_group'
        ,'label' => 'Page Modules'
        ,'value' => 'none'
        ,'add_more' => true
        ,'fields' => array(
          array(
            'type' => 'select'
            ,'field' => 'module_select'
            ,'label' => 'Select a Module'
            ,'columns' => 12
            ,'choices' => array(
              'none' => 'Select a Module to add'
              ,'module' => 'Editor'
              ,'repeating_module' => 'Repeating Textarea'
            )
          )
          ,array(
            'type' => 'editor'
            ,'field' => 'module_editor'
            ,'columns' => 12
            ,'options' => array(
              'wpautop' => true
              ,'media_buttons' => false
              ,'tabindex' => ''
              ,'editor_css' => ''
              ,'editor_class' => true
              ,'teeny' => false
              ,'dfw' => false
              ,'tinymce' => true
              ,'quicktags' => true
            )
            ,'conditions' => array(
              array(
                'field' => 'module_group:module_select'
                ,'value' => 'module'
              )
            )
          )
          ,array(
            'type' => 'textarea'
            ,'field' => 'module_title'
            ,'label' => 'Module title:'
            ,'columns' => 12
            ,'add_more' => true
            ,'attributes' => array(
              'class' => 'large-text'
              , 'rows' => 2
            )
            ,'conditions' => array(
              array(
                'field' => 'module_group:module_select'
                ,'value' => 'repeating_module'
              )
            )
          )
        
        )
      ));
  • #5735

    pwwwpwww
    Participant

    I think I figured it out. It’s a bit rough, but seems to handle the above example:

    $pwww_builder = get_post_meta( get_the_ID(), 'module_group', true ); 
    
    foreach ( $pwww_builder as $pwww_build ) {
    
        // Print out the first module type
        echo '<p>' . $pwww_build['module_editor'] . '</p>';
            
            //The next module is an add-more field - lets dig a bit deeper
            $pwww_buildtitle = $pwww_build['module_title']; 
        
                foreach ( $pwww_buildtitle as $pwww_title) { 
                    
                    // Print out the second module type
                    echo '<h2>' . $pwww_title . '</h2>';
                    }                                                  
    }

    I’ll have a go at creating my own page builder in the next day or two – I can think of at least 8-10 modules that would be useful for building those one-off landing pages that are normally a time drain. If you can leave this thread open for a few days, I’m sure I’ll be back with more questions / amateur code gibberish. I suspect my copypasta will fail miserably one I try and do fancier things.

  • #5773

    Steve
    Keymaster

    @pwwwpwww– This is great. You need to create two loops…which you did.

    Closing Ticket.

The topic ‘Nested addmore repeater fields – aka page builder – displaying on the frontend’ is closed to new replies.