How can I export all locations to CSV?

How can I export all locations to CSV?

Update November 1, 2022: The Export & Import Feature is now available (v1.3.0) in the PRO version.

The following solution is not recommended anymore.

This is just a temporary solution until the Export feature is available. This might not work in all cases!
With some PHP knowledge you can export the data of all locations to a CSV file. You can manage the fields you want to export. The CSV file will be saved in the root folder of your website. So please be aware that this file may contain information that you don’t want to be publicly available.

Note that at least version 1.2.22 of the Open User Map plugin is required for this to work.

Here is how to proceed:

Step 1: Add the following PHP code to your functions.php file in your theme:

/**
 * export all oum-locations to a csv file
 */
add_action( 'init', function() {

    if(isset($_GET['export_oum_locations'])) {
    
        // manage your field values that you want to export
        $fields = [
            'title',
            'type',
            'text',
            'lat',
            'lng',
            'address',
            'author_name',
            'author_email',
            'user_id',
            'CUSTOM FIELD LABEL'
        ];

        // set filename
        $filename = 'oum-locations.csv';
    
        $data = [];
    
        $query = array(
            'post_type' => 'oum-location',
            'posts_per_page' => -1,
            'fields' => 'ids',
        );
    
        $locations = get_posts($query);
    
        $data[] = $fields;
    
        foreach($locations as $location_id) {
            $row = [];
            
            foreach($fields as $field) {
                $row[] = oum_get_location_value($field, $location_id);
            }
    
            $data[] = $row;
        }
    
        // open csv file for writing
        $f = fopen($filename, 'w');
    
        foreach($data as $item) {
            fputcsv($f, $item);
        }
    
        // close the file
        fclose($f);
    }

}, 99);

Please edit the $fields variable according to your needs. If you want to export custom fields add the label of each custom field.

Step 2: Open your website in the browser with a ?export_oum_locations parameter attached:

https://your-domain.com/?export_oum_locations

Step 3: This will create a file oum-locations.csv directly to the root folder of your website. Download and delete it as this file may contain sensitive user information. Don’t forget to remove the additional code from the functions.php file as well!

https://your-domain.com/oum-locations.csv
EN