How to display form entries

Created by Phil Kurth, Modified on Tue, 31 Jan, 2023 at 10:52 AM by Phil Kurth

Advanced Forms entries are a custom post type with the type af_entry. ACF fields are stored against the entry post using ACF's update_field() function and a reference to the form key is stored in the entry's postmeta under the key entry_form

Given this standard WordPress data structure, you may use normal WordPress queries and ACF's template functions to display entry data as needed. 


The following is an example of how to query entries for a specific form and list the entry data in a HTML table.


<?php
// Query the form entries using get_posts(). We use a `meta_query` here to specify the form key we want entries for.
$entries = get_posts( [
  'post_type' => 'af_entry',
  'posts_per_page' => - 1,
  'meta_query' => [
    [
      'key' => 'entry_form',
      'value' => 'form_63603dfd5f7d2',
    ]
  ]
] );

// Loop through the entries and output the data using WordPress and ACF template functions.
if ( $entries ): ?>
  <table class="entries">
    <tr>
      <th>Entry ID</th>
      <th>Entry #</th>
      <th>First Field</th>
      <th>Second Field</th>
    </tr>
    <?php foreach ( $entries as $entry ): ?>
      <tr>
        <td><?= $entry->ID ?></td>
        <td><?= get_the_title( $entry ) ?></td>
        <td><?php the_field( 'first_field', $entry->ID ); ?></td>
        <td><?php the_field( 'second_field', $entry->ID ); ?></td>
      </tr>
    <?php endforeach; ?>
  </table>
<?php endif; ?>

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article