Support

Account

Forum Replies Created

  • Tried to get this working again and i seem to get it. It’s an array inside and array so i used this code to pull out the data (i used the ZIP file i have above).

     
    <?php if( have_rows('modules_all') ): 
      while( have_rows('modules_all') ): the_row();
    
              $checkbox = get_sub_field('is_custom_modules');
              if($checkbox) { // is yes use custom modules ?>
    
                   <?php
    
                    //print_r(get_sub_field('modules_custom_reusable'));
                    $contentArray = get_sub_field('modules_custom_reusable');
                    
                    $contentTitle = $contentArray['modules_custom'][0];
                    $contentTitle = print_r($contentTitle['content_title']); 
    
                    ?>
    
                    <?php $contentTitle; ?>
    

    You can uncomment the first line to see how the array looks like or use var_dump instead print_r.

    It may not be the perfect solution as i’m not a real PHPer but it seems to be working/taking me further.

  • Would be nice to have these repeated fields as “partials”.

    If you have 10+ flexible fields and most of them have same fields for like title with h1,h2,h3 setting etc. Updating these could be a pain on all 10+ flexible fields.

    Also in the php templates, you can just create a partials/ folder and have just the fields there for the specific partial field group. You just call them to the flexible php templates and it will be a lot easier to update all of them.

    Although i think this is just different approach as we don’t have div containers/rows/columns for the layout building so we need to group sections together that way. Which is nice too though as that approach is close to the drag & drop builders.

  • @floflo91 thanks, i thought so too and had quite a few similar tries yesterday, but it seems it doesn’t want to pick up the if( have_rows(‘flexible’) ):

    added the custom fields export/template.php i’m using with your example.

    The logic is there, it just doesn’t pick it up :/

  • Ah, sorry, must have explained it bad. I made a PDF with the logic/concept behind it.

    Hope it helps 🙂 If there is a better/easier way to do this, that would be great.

  • @floflo91 thanks for the help! That one works well for the normal fields inside the Reusable field but not for a flexible field inside a Reusable field.

    i tried to use print_r
    <?php print_r(get_sub_field('modules_custom_reusable')); ?>
    which outputted:

    Array ( [modules_custom] => Array ( [0] => Array ( [acf_fc_layout] => module_sample [content_title] => text field inside flexible ) ) [content_title] => text field outside flexible )

    So it is picking up the content of the flexible field i just don’t know how to pull them out separately and apply the layout fields. :/ Will try it more.

    Here are the templates for the normal fields in case anyone will need them.

    Inside a repeater:

          <?php if( have_rows('repeater') ): ?>
    
              <?php while( have_rows('repeater') ): the_row(); ?>
    
                  <?php
                  if (get_sub_field('reusable_field')) {
                    foreach (get_sub_field('reusable_field') as $p) {
                      echo $p;
                      the_sub_field('subfieldName');
                      the_sub_field('subFieldName2');
                    }
                  } ?>
    
              <?php endwhile; ?>
    
          <?php endif; ?>

    inside a flexible field type:

    <?php
    
    if( have_rows('flexible') ):
    
        while ( have_rows('flexible') ) : the_row();
    
            if( get_row_layout() == 'layout_flexible' ): ?>
    
                  <?php
                  if (get_sub_field('reusable_field_group_')) {
                    foreach (get_sub_field('reusable_field_group') as $p) {
                      echo $p;
                      the_sub_field('subfieldName');
                      echo "<br>";
                      the_sub_field('subFieldName2');
                    }
                  } ?>
    
           <?php elseif( get_row_layout() == 'other' ):
    
            endif;
    
        endwhile;
    
    else :
    
    endif;
    
    ?>
  • Hi @jonathan, i was thinking more of a checkbox with the sync options (i still want to delete/readd fields on some other fields) :).

    In my case i don’t want to use WPMU, it’s just that i have many websites to manage/create and want to have my own flexible content fields, which are made into bootstrapped modules (like the drag & drop ones work).

    But updating them to each site would be great, but some of those sites require either some custom flexible content fields or something else added (based on content/product etc.) and those would get overwritten with the sync (the problem is that i can’t create 2 different flexible module groups that have the drag& drop ordering feature etc.). The master was just a name for the most updated custom fields.

    So in the end i would be able to keep the ACF and templates clean throughout the site and update just by copy/pasting the files and syncing the changes. I did stumpble on this improvement when trying to figure out one of my problems here. 🙂

    The child theme approach seems interesting but in my case it may make everything more complex as i use the roots.io starter theme.

    I think that one solution to this workflow would be to create a plugin with all the acf fields etc inside it, but i haven’t been able to do that with my limited php skills.

  • @floflo91 hm.. couldn’t make it to work.

    I also started from scratch and made a field group with just 2 text fields.

    Made a second field group with the reusable group and called the first one.

    Made 2 tests in the template:

    Test A
    <?php the_field('reusable_field_group_for_text'); ?>
    
    Test B
    <?php
    if( have_rows('reusable_field_group_for_text') ):
    while ( have_rows('reusable_field_group_for_text') ) : the_row();
    echo "TEST";
    endwhile; endif;
    ?>

    TEST A output was and array of both text fields, although i would want to call them separately.
    TEST B code didn’t work so maybe i just don’t know how to call the Reusable field type and it’s contents correctly :/ Even without any repeater/flexible.

    Too bad the plugin docs don’t have any usage code for it.

  • @floflo91 thanks for the help!

    I used the plugin you mentioned and the logic seems fine on the backend etc.

    A Repeater field (so i can mix and match the flexible content)
    A.1 Checkbox to choose to have flexible content A or B
    A.2 Reusable field of Flexible content A (core modules for use on other websites)
    A.3 Reusable field of Flexible content B (specific custom modules used for specific website).

    The frontent/template part is a bit tricky.

    Repeater field
    – checkbox
    — Reusable Field group (ex. modules_main_reusable)
    — Flexible content field (ex. modules_main)
    —- Field types for the flexible layout

    How should i call the modules_main_reusable field type? like this:

    if( have_rows('modules_main_reusable') ):
    while ( have_rows('modules_main_reusable') ) : the_row();

    And then add the flexible repeater code inside it?

    
                        <?php
                        if( have_rows('modules_main') ):
    					while ( have_rows('modules_main') ) : the_row(); ?>
                              <?php  if( get_row_layout() == 'module_sample' ): ?>
                                <?php get_template_part('templates/modules-main/module', 'sample') ?>
                              <?php endif; ?>
                         <?php endwhile; endif; ?>
    
  • @timh Ah thanks, so maybe it just doesn’t work with the reusable field group being a flexible content.

    I thought the reusable field group works as a “row” so you could add more html etc. to the template.

  • @timh Any tips on how you used that plugin in the php template? The docs for it are almost nonexistent. Have a bit of trouble (setting it up).

    Thanks

  • I tried couple of things, found this plugin https://github.com/mvpdesign/acf-reusable-field-group which in a way would be possible to make it but it doesn’t seem to work (attached the fields structure).

    and here is the code i’m running through the template:

    
    <?php
    
    // check if the repeater field has rows of data
    if( have_rows('modules_all') ):
    
        // loop through the rows of data
        while ( have_rows('modules_all') ) : the_row(); ?>
    
        <?php
        $checkboxcustom = get_sub_field('is_custom_modules');
        if($checkboxcustom) { // is yes ?>
        CUSTOM
                        <?php
                        if( have_rows('modules_custom') ):
    
                            while ( have_rows('modules_custom') ) : the_row(); ?>
    
                              <?php  if( get_row_layout() == 'module_sample' ): ?>
    
                                <?php get_template_part('templates/modules-custom/module', 'sample') ?>
    
                              <?php endif; ?>
    
                          <?php endwhile; ?>
    
                         <?php endif; ?>
    
        <?php } else { ?>
        MAIN
                        <?php
                        if( have_rows('modules_main') ):
    
                            while ( have_rows('modules_main') ) : the_row(); ?>
    
                              <?php  if( get_row_layout() == 'module_main' ): ?>
    
                                <?php get_template_part('templates/modules-main/module', 'main') ?>
    
                              <?php endif; ?>
    
                          <?php endwhile; ?>
    
                         <?php endif; ?>
    
        <?php } ?>
    
       <?php endwhile;
    
    else :
    
    endif;
    
    ?>
    

    IT seems to be working nicely for the Main fields but not the Custom one, as they are not beeing displayed.

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