Support

Account

Home Forums ACF PRO Displaying data in table for different records

Solving

Displaying data in table for different records

  • On a site I require a table of a standard layout that is used for many different product records.

    LEFT column is fixed labels but I might need to change the text, add more rows/labels, delete rows etc

    RIGHT column I want a select field in each cell that contains choices to select from I set up, i.e choice differs depending on the product record, but a limited range hence the select list*. Shown in image is a ‘selected choice’ (drop-downs not shown) Again these will want to be edited, added to etc.

    Would I set up a table acting as a template or master table which contains virtually as the attachment shows, and is editable as explained, and then Copy this for each record I need, then adjusting the select choices for the copy table/record/s. Then call in the whole table to the product record page.

    Not quite sure of the extent to which I can use ACF repeater for this. The repeater has two sub fields for this so I can’t seem to see if I can add individual select fields for each row, as each row requires its own select Choices.

    *except File Title and Image Title, which will be text fields

    Thanks,

  • The layout of fields that you’re looking for is not currently possible in ACF, that is a table with the labels on the left and fields on the right.

    With ACF5, when setting up a field group in ACF you can set Label placement for a field group to left aligned and this will for the most part create what looks like a table with labels on the left and values on the right.

    A repeater would probably not be the right method to create what you’re looking for.

  • Hi John,

    I’ve been playing around with templates (unacquainted when I posted before) and as happens with these things it comes together and makes more sense. Rather than trying to create the whole solution in ACF I realize that instead it is more flexible for me to create the table markup in the template and just call in individual ACF text fields that have the value I want.

    I have 1 text field for each of the left columns labels and the assortment of fields I need for the values in the right column of the table. These values are being shown in the templates table cells where needed using the ‘is_page’ WordPress conditional statement at this stage and the page/s that represent my products are all displaying great and in the last several week my ACF has become overloaded with all types of content from one word text expressions to sentences to multiple sentences, repeaters, tables, images, galleries etc etc and the functions. I don’t think I’ve learned so much in a short time before! Before this I was starting to think it’s impossible to have a decent website now I feel like a shoo-in.

    If I use the repeater I need to accept the repeater ‘as is’ don’t I (as it is laid out in ACF). The template requires the table code anyway. But the repeater is good if it is used as a block for many different products. In fact as many of my products are the same I am simply calling a complete repeater for many straight out of ACF. But when the values in the table start becoming different it will behoove me to call in each of the text fields in the other arrangement, rather than having lots of different repeaters that have duplicate data.

    The is_page setup seems quite basic and long-winded but for a non-coder like me, now I’ve investigated it, is dead easy and I understand it’s robust. I’ve replaced some other unreliable functions like the http referrer by simply creating additional WordPress pages and using the is_page conditional tag. this way I can use the ACF fields accordingly. I don’t think I can use session variables from the product pages as they are done from another shopping cart plugin and it make updating hard or something.

  • You may try this code. It’s works for me.

    <table class="ACFTable">
    <col width="40%">
    <col width="60%">
    <thead>
    <tr>
    <th>Field Heading</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <td>Field Title</td>
    <td><?php the_field( 'field_value' ); ?></td></tr>
    </tbody>
    </table>
Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Displaying data in table for different records’ is closed to new replies.