WPML
สถานะ
เปิด
แท็กหัวข้อ
Bug

ภาพรวมของปัญหา

เมื่อคุณกำหนดคำศัพท์ให้กับโพสต์ WordPress จะจัดเก็บยอดรวมสะสมของจำนวนโพสต์ที่คำศัพท์เฉพาะนั้นถูกกำหนดไว้

หากคุณลบคำศัพท์ออกจากบางโพสต์ จำนวนนับก็จะลดลง หากการตั้งค่ากำหนดให้ซิงค์คำศัพท์ คำศัพท์ที่แปลแล้วจะถูกลบออกจากโพสต์ที่แปลแล้ว แต่จำนวนนับจะไม่ลดลง

วิธีแก้ปัญหาชั่วคราว

คุณสามารถเพิ่มโค้ดต่อไปนี้ (ผ่านปลั๊กอิน หรือไฟล์ functions.php ของธีม) เพื่อบังคับให้คำนวณจำนวนเทอมใหม่สำหรับการแปล:

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);

ปัญหาที่ทราบแล้วทั้งหมด →