PHP code example of hamworks / simple-csv-exporter

1. Go to this page and download the library: Download hamworks/simple-csv-exporter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hamworks / simple-csv-exporter example snippets


use HAMWORKS\WP\Simple_CSV_Exporter\Data_Builder;
add_action( 'simple_csv_exporter_created_data_builder', 
	function ( Data_Builder $data ) {
		// Remove column.
		$data->append_drop_column( 'page_template' );
		// Add custom field column.
		$data->append_meta_key( 'my_meta_key' );
	}
);

add_action( 'simple_csv_exporter_data_builder_for_wp_posts_pre_get_posts', 
	function ( WP_Query $query ) {
		$query->set( 'order', 'ASC' );
	}
);

add_filter( 'simple_csv_exporter_data_builder_for_wp_posts_get_post_meta_fields',
	function ( array $fields ) {
		foreach (
			array(
				'your_flag',
			) as $key
		) {
			if ( isset( $fields[ $key ] ) ) {
				$fields[ $key ] = ! empty( $fields[ $key ] ) ? 'TRUE' : 'FALSE';
			}
		}
		return $fields;
	}
);

add_filter(
	'simple_csv_exporter_data_builder_for_wp_posts_row_data',
	function ( $row_data, $post ) {
		$row_data['permalink'] = get_permalink( $post );
		unset( $row_data['comment_status'] );
		return $row_data;
	},
	10,
	2
);