Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Our wait time is higher than usual, please make sure you are meeting the minimum requirement - https://wpml.org/home/minimum-requirements before you report issues, and if you can take a look at current Known Issues - https://wpml.org/known-issues/. Thank you.
Sun Mon Tue Wed Thu Fri Sat
10:00 – 14:00 10:00 – 14:00 10:00 – 14:00 10:00 – 14:00 10:00 – 14:00 - -
16:00 – 20:00 16:00 – 20:00 16:00 – 20:00 16:00 – 20:00 16:00 – 20:00 - -

Supporter timezone: Asia/Jerusalem (GMT+03:00)

This topic contains 0 replies, has 1 voice.

Last updated by Itamar 1 day, 17 hours ago.

Assisted by: Itamar.

Author Posts
March 25, 2025 at 11:55 am #16857178

John-Pierre Cornelissen

Background of the issue:
I am a web designer and I would like to be able to create a CSV file with an estimate of the number of words that needs to be translated, so I can send it to the customer for approval. At the moment I create a screenshot (attached) with the Word count from the Translation Dashboard, but that sometimes needs multiple screenshots from multiple sections and that looks unprofessional.

I would like the report to have a list with the following columns, example attached:
- selected item
- item type (ie each page)
- the word count of the item

I want this to be in a CSV file, so I can use it in Excel to add a calculations of the expected costs for each language (depending on the translation engine or translation service).

Symptoms:
There is no direct feature in WPML to generate a CSV file with word count estimates for translation.

Questions:
How can I generate a CSV file with a list of selected items, item types, and word counts for translation estimates?

» Feature request

March 27, 2025 at 9:13 am #16866986

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

I've passed on your request to our second-tier supporters. When I have their reply, I'll update you.

I appreciate your patience.
Itamar.

March 30, 2025 at 2:21 pm #16876645

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

Our second-tier supporter suggests the following: You can write simple PHP code that will take the value of ID, Title, and the number of words in the post meta _wpml_word_count and output it to a CSV file. Here is a sample code generated by ChatGPT.

function export_word_count_to_csv() {
    // Adjust your query args as needed
    $args = array(
        'post_type'      => 'post', // Change to your desired post type
        'post_status'    => 'publish',
        'posts_per_page' => -1,
        'orderby'        => 'ID',
        'order'          => 'ASC',
    );

    $query = new WP_Query($args);

    if ($query->have_posts()) {
        // Set headers to force download CSV
        header('Content-Type: text/csv');
        header('Content-Disposition: attachment;filename=word-count-export.csv');

        $output = fopen('<em><u>hidden link</u></em>', 'w');

        // Output header row
        fputcsv($output, array('ID', 'Title', 'Word Count'));

        // Loop through posts
        while ($query->have_posts()) {
            $query->the_post();

            $post_id    = get_the_ID();
            $title      = get_the_title();
            $word_count = get_post_meta($post_id, '_wpml_word_count', true);

            // If no value, fallback to 0
            if (!$word_count) {
                $word_count = 0;
            }

            fputcsv($output, array($post_id, $title, $word_count));
        }

        fclose($output);
        exit; // stop script after CSV output
    } else {
        echo 'No posts found.';
    }

    wp_reset_postdata();
}

// You can call this function via a custom admin page, WP-CLI command,
// or hook it to an action like 'init' with a conditional check for a URL param
// Example: <em><u>hidden link</u></em>
add_action('init', function () {
    if (is_admin() || !isset($_GET['export_word_count'])) {
        return;
    }
    export_word_count_to_csv();
});

The following are the steps you need to follow.

1. Add this code to your theme's functions.php file or in a custom plugin.

2. Visit your site with the ?export_word_count=1 query string in the URL (e.g., hidden link).

3. A CSV download should start with the structure:

I tried it on my test, and it works for posts.
Please note that you may need to add other post types to adjust it to your needs.

Regards,
Itamar.