WPML
Status
Open
Topic tags
Bug

Overview of the issue

When you assign terms to posts a running total of the number of posts a particular term has been assigned to is stored by WordPress.

If you remove a term from some post then the count is reduced. If settings are for terms to sync then the translated term will be removed from the translated post, but the count does not go down.

Workaround

You can add the following code snippet (via a plugin, or your theme’s functions.php file) to force the term counts to recalculate for the translations:

add_action( 'deleted_term_relationships', function($object_id, $tt_ids, $taxonomy){

    $trids = array();
    $translated_tt_ids = array();

    foreach ($tt_ids as $tt_id) {
        $trids[] = apply_filters( 'wpml_element_trid', NULL, $tt_id, 'tax_'.$taxonomy );
    }

    foreach ($trids as $trid) {
        $translations = apply_filters( 'wpml_get_element_translations', NULL, $trid, 'tax_'.$taxonomy );
        foreach ($translations as $lang => $translation) {
            $translated_tt_ids[] = $translation->element_id;
        }
    }    

    $translated_tt_ids = array_diff( $translated_tt_ids, $tt_ids );

    if ( count( $translated_tt_ids ) ) {
        wp_update_term_count( $translated_tt_ids, $taxonomy );
    }

}, 11, 3);

All known issues →