Home › Forums › General Issues › Dynamic Table with ACF
Hey Community,
I would like to create a dynamic table using Advanced Custom Fields.
Unfortunately, the whole thing still looks a little “shot” …
Can someone help me?
How to proceed:
I have created a new Post_Type.
In ACF I created a new field group that was assigned to the associated post_type as position.
Then I created a new * .php file with a table.
Current offers are shown in this table.
Unfortunately, this only works “conditionally”.
For example, only a maximum of 5 lines are shown, which should actually be 10.
Then the “Model” column is not filled in at all.
In addition, a new “heading” is created for each new line.
Would be nice if someone could help me here …
<?php
$args = array(
'post_type' => '3d_drucker',
//'orderby' => 'title',
//'order' => 'ASC',
);
$preisvergleich = new WP_Query($args);
if($preisvergleich->have_posts()) : while($preisvergleich->have_posts()) : $preisvergleich->the_post();
?>
<?php
// Wenn mindestens 1 Datensatz vorhanden ist
// Platzierung aus Feld laden
$platzierung = get_field( 'platzierung' );
// 3D Drucker aus Feld laden
$bezeichnung = get_field( 'modell' );
// Listenpreis aus Feld laden
$listenpreis = get_field( 'listenpreis' );
// Aktionspreis aus Feld laden
$aktionspreis = get_field( 'aktionspreis' );
// Gutschein aus Feld laden
$gutschein = get_field( 'gutschein' );
// Angebot aus Feld laden
$angebot = get_field( 'angebot' );
// Info aus Feld laden
$info = get_field( 'info' );
echo "<table>";
echo "<thead>";
echo "<tr>";
echo "<th>Platzierung</th>";
echo "<th>3D Drucker</th>";
echo "<th>Listenpreis</th>";
echo "<th>Aktionspreis</th>";
echo "<th>Aktion / Gutschein</th>";
echo "<th>Zum Angebot</th>";
echo "<th>Infos zum Gerät</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
echo "<tr>";
echo "<td>$platzierung</td>";
echo "<td>$modell</td>";
echo "<td>$listenpreis </td>";
echo "<td>$aktionspreis </td>";
echo "<td>$gutschein</td>";
echo "<td>$angebot</td>";
echo "<td>$info</td>";
echo "</tr>";
echo "</tbody>";
echo "</table>";
?>
<?php endwhile; endif; wp_reset_postdata(); ?>
You’re table start and table end markup needs to be outside of the loop
if ($preisvergleich->have_posts()) {
// ouptut start of table here;
?>
<table>
<thead>
<tr>
<th>heading 1</th>
<th>etc...</th>
</tr>
</thead>
<tbody>
<?php
while ($preisvergleich->have_posts()) {
$preisvergleich->the_post();
// output each row of the table here
} // end while
// output end of table here
?>
</tbody>
</table>
<?php
} // end if have posts
The topic ‘Dynamic Table with ACF’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.