Building a cornerstone template Including flexible and repeating content from ACF PRO

I am setting up a custom post where the author can create data using repeating and flexible content from ACF pro forms. The data is a mix of text (different for Headings and paragraphs), images, links and occasional videos. How do I integrate this setup into cornerstone where the layout and elements depends on content that varies in both type and number?

The goal is to create a formatted page with data including different headings, text, images and occasional videos and save it in a template that the author just loads into their post.

Hello Kaushal,

Thanks for writing in!

To get your idea be realized, go to X > Global Blocks, and create your layout. You will have to use text and other elements supplied with the dynamic content feature so that the ACF Pro data will be displayed on the block. You can then save this block as a template. Once you create a page, you can simply use the block to display the ACF Pro data. To learn more about the Dynamic Contents, kindly check this out:

We would love to know if this has worked for you. Thank you.

Hello Reunei,

Thanks for the response…!

I have been using Global blocks as well as the dynamic content feature and integration of single data fields has never been an issue in cornerstone. It works flawlessly.

However, the problem is looping through data fields of repeater and flexible data content from the ACF forms. It can not be done without using ‘while’ and ‘if’ conditions. is there any way to implement this logic for a specific type of post? for example, particular sections of portfolio posts.

If it can be done, where do the codes go? and how do I target them? Can it be done by adding some advanced custom coding to the child theme functions or it has to be added into the post type somewhere?

Something like this maybe? (Code taken from here)

<?php if( have_rows('repeater_field_name') ): ?>

<ul>

<?php while( have_rows('repeater_field_name') ): the_row(); ?>

    <li>sub_field_1 = <?php the_sub_field('sub_field_1'); ?>, sub_field_2 = <?php the_sub_field('sub_field_2'); ?>, etc</li>
    
    <?php 
    
    $sub_field_3 = get_sub_field('sub_field_3'); 
    
    // do something with $sub_field_3
    
    ?>
    
<?php endwhile; ?>

</ul>
<?php endif; ?>

But I’m not sure where and how. Some support will be great here.

Thanks

I’d like to add a little more. These fields show up as arrays while being added in the cornerstone dynamic element and rendered as “Array, Array, Array, Array, Array… and so on”.

So I wanted to try something and tried what goes somewhat like…

<?php

if( have_rows('some_list') ):
     $line = 0;

    while( have_rows('some_list') ) : the_row();
          $line++;

        $unit_1 = get_sub_field('unit_1');
        $unit_2 = get_sub_field('unit_2');
        $unit_3 = get_sub_field('unit_3');
        $unit_4 = get_sub_field('unit_4');
        $unit_5 = get_sub_field('unit_5');
        echo "Line ".$line." - ".$unit_1." ".$unit_2." ".$unit_3.", ".$unit_4." <a href='".$unit_5."'>link</a>";


    endwhile;
    
endif;
?> 

Not sure where to put the code though. I tried in a couple of places, but it didn’t work.

Hello Kaushal,

Thanks for the updates. Please be aware that custom coding is way beyond the scope of our support. Our support only covers getting your site setup, bug fixes and minor cosmetic changes. A PHP code is not supported within Cornerstone as well. We highly recommend that you create your PHP code into a shortcode so that the resulting shortcode can be added inside Cornerstone through a text element or content area element. You might need to check out this codex on how to create your own shortcode:

Note: We are unable to provide support for customizations under our Support Policy. If you are unfamiliar with code and resolving potential conflicts, you may select our One or Care service for further assistance.

Thank you for your kind understanding.

Hello Ruenel,

I did figure it out, with a little help from ACF documentation. And yes, I added those shortcakes.

I have another question. What is the input date format for the countdown? I’d like to set it externally. I tried a few formats, but none seem to be working.

Regards,
K

Okay… I figured the input date format, but how do I input it? I tried different ways including the dynamic data input as well as a shortcode. But the only ways that seem to work are using its own calendar or typing directly into the field.

Hey Kaushal,

Please check the UI you can use in the Field Types documentation of ACF here https://www.advancedcustomfields.com/resources/#field-types

If you need something other than those types, you will need to consult with a developer.

Hope that helps and thank you for understanding.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.