Online sales are on the rise. Ever since the coronavirus pandemic broke out, people have switched to ecommerce. It has […]
How to create and style an HTML Table in Oxygen builder using dynamic data from ACF Repeater table.
With the recent updates of Oxygen bringing the Repeater fields to the builder. It's a great addition, which opens up to a lot of possibilities. One particular use that I needed for the Oxygen Repeater module (using ACF Repeater) is to output the results as a table.
The builtin Repeater in Oxygen builder doesn't allow for such manipulation at the moment. However, there's a workaround solution to get Oxygen builder output ACF Repeater table. Which you can style further with the magic of CSS.
Step 1: Starting ACF Repeater table
Create your custom repeater fields, in this example I'll create a simple [subject] [result] table. The method can be replicated to any number of columns.
Create a field group:
Label: Subject & Results
Field name: r_subject_&_results
Field type: Repeater
Expand the Repeater field and add the nested fields. In this case will be:
Label: Subject with field name: r_subject.
Label: Result with field name: r_result
Step 2: Using Oxygen Builder
Create the template, page, any other CPT you want to add the table to.
Insert the Code Module, and add below PHP code:
r_subject_&_results = ACF Repeater
r_subject = Field 1
r_result = Field 2
<!-- repeater fields table output-->
$i = 0;
if( have_rows('r_subject_&_results') ): ?>
<?php while( have_rows('r_subject_&_results') ): the_row(); $i++;
$post = get_sub_field('r_subject');
if( empty($post) )
setup_postdata( $post );
<?php if( $i == 1 ): ?>
<?php endif; ?>
<td><?php the_sub_field('r_subject'); ?></td>
<td><?php the_sub_field('r_result'); ?></td>
<?php if( $i == 2 ): $i = 0; ?>
<?php endif; ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
The above code will basically create a table based on the ACF repeater fields r_subject and r_result
Step 3. Applying CSS Styles to the Table
As you can see in the above code, the table is created and given a class of r-table
And just like an HTML Table it has < th > and < tr > that you can style further.
This is easily done with CSS. Here's a reference to CSS Tables styling on W3School.
if you have any question, feel free to write in the comments below.
Starting your own online business sounds both promising and challenging because it may have its advantages and disadvantages as well. […]
Email marketing might be one of the oldest tricks in the digital marketing book, but it’s still going strong. It’s […]
Top-notch copywriting is very similar to having a great salesperson selling your products or services around the clock. By learning […]
The current COVID-19 virus has one thing in common with every other traumatic event throughout human history. It will eventually […]
If you are starting a business and are working to build and promote it, there are some important things to […]
Social media video marketing is the hottest trend and the most effective marketing tool. It helps reach masses of the […]