• Resolved nepf

    (@nepf)


    I whould like to export a query with the_title() and some get_post_meta() to a csv-file.
    I think fputcsv() is the rigth PHP-function, but i have no idea how to put this into the loop.
    Has anyone helpful hints for me?
    Thank you.

Viewing 1 replies (of 1 total)
  • Thread Starter nepf

    (@nepf)

    solved it by my own.
    Maybe it’s helpfull for someone

    <?php $fh = fopen( 'wp-content/uploads/export.csv', 'w'); ?>
    <?php $person = array(); ?>
    
    	<?php while ( have_posts() ) : the_post(); ?>
    		<?php
    			$name = get_post_meta($post->ID, 'nepf_name', true);
    			$adress = get_post_meta($post->ID, 'nepf_adress', true);
    			$hobby = get_post_meta($post->ID, 'nepf_hobby', true);
    
    			$person[] = array($name, $adress, $hobby);
    		?>
    	<?php endwhile; ?>
    
    <?php
    foreach($person AS $dataset) { fputcsv($fh, $dataset, ';'); }
    fclose($fh);
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Export Query to csv – fputcsv’ is closed to new replies.