Home Forums General Issues Comma separated array values


Comma separated array values

  • Hey Community,

    I know this thread has been asked a few times, but unfortunately I can’t get comma-separated values.

    i think the problem is “in my table”.
    Because without a table, all the solutions found so far work straight away …

    $args = array(
    'post_type' => '3d_drucker',
    'posts_per_page' => '100',
    'orderby' => 'Title',
    'order' => 'ASC',
    $Vergleichstabelle = new WP_Query($args);
    if($Vergleichstabelle->have_posts()) {
    				<table class="wp-list-table widefat fixed striped posts sortable">
    						<th scope="col" id="title" class="manage-column column-title column-primary sortable desc" style="cursor: pointer; width: 230px;">Bezeichnung</th>
    						<th scope="col" id="5df4849c8e9c9" class="manage-column column-5df4849c8e9c9 sortable desc" style="cursor: pointer">Hersteller</th>
    						<th scope="coL" id="5df4ffb88b01d" class="manage-column column-5df4ffb88b01d sortable desc" style="cursor: pointer">Typ</th>
    						<th scope="col" id="5df4849c8df18" class="manage-column column-5df4849c8df18" style="cursor: pointer; width: 250px;">Filament</th>
    						<th scope="col" id="5df85bd34be85" class="manage-column column-5df85bd34be85 sortable desc" style="cursor: pointer">Verfahren</th>
    						<th>Infos zum Gerät</th>
    	   while ($Vergleichstabelle->have_posts()) {
    	  // Wenn mindestens 1 Datensatz vorhanden ist
    // Platzierung aus Feld laden
        $bezeichnung = get_field( 'bezeichnung' );
    // 3D Drucker aus Feld laden
        $hersteller = get_field( 'hersteller' );
    // Listenpreis aus Feld laden
        $typ = get_field( 'typ' );    
    // Aktionspreis aus Feld laden
     //   $filament = get_field( 'filament' );  
        $filamente = get_field('filament');
    	foreach($filamente as $filament)
    // Gutschein aus Feld laden
        $verfahrens = get_field( '3ddruck-verfahren' );  
    	foreach($verfahrens as $verfahren)
    // Info aus Feld laden
        $info = get_field( 'info' ); 
    					echo "<tr>";
    						echo "<td>$bezeichnung</td>";
    						echo "<td>$hersteller</td>";
    						echo "<td>$typ </td>";
    						echo "<td>$filament </td>";
    						echo "<td>$verfahren</td>";
    						echo "<td>$info</td>";
    					echo "</tr>";
    } // end if have posts
  • I’m still not further … I found the following code, but it only shows “array” …. really stupid

        $filamente = get_field( 'filament' );
    		foreach($filamente as $filament):
    	$filament_fields = get_field('$filament', $filament);
    	if( $filamente_fields ):
    		$filament_fields_slugs = array_column($filament_fields, 'slug');
            $data_filament_slugs = implode(', ', $filament_fields_slugs);
  • If the ‘filament’ field is a straight repeater, I don’t think you need the foreach loop:

    try this:

    $filamente = get_field( 'filament' );
    	if( $filamente ):
    	    $data_filament_slugs = implode(",", array_column($filamente, 'slug') );
  • Hey bosoxbill,
    thanks for your answer!

    unfortunately with this code my table remains empty …
    but with that you gave me food for thought.

    i got it!
    the following code works!

    $filamente = '';
    $filament = get_field('filament');
    if ($filament) {
      $filamente = implode(', ', $filament);
    echo "<td>$filamente </td>";
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.