Home Forums General Issues Dynamic Table with ACF


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 …

    $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();
    	  // 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;
             <th>heading 1</th>
      while ($preisvergleich->have_posts()) {
        // output each row of the table here
      } // end while
      // output end of table here
    } // end if have posts
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Dynamic Table with ACF’ is closed to new replies.