- 状态
- 未解决
- 主题标签
- 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);