taxonomy WP). * `categorie` est volontairement absent (déjà synchronisé par Pods). */ function thalim_pod_tax_sync_fields(): array { return [ 'programmes_de_recherche' => 'programme_de_recherche', 'etiquettes' => 'post_tag', 'axes_thematiques' => 'axe_thematique', ]; } add_action( 'save_post', 'thalim_sync_pods_taxonomy_relations', 99, 2 ); function thalim_sync_pods_taxonomy_relations( $post_id, $post ) { if ( ! ( $post instanceof WP_Post ) || 'post' !== $post->post_type ) { return; } if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) { return; } foreach ( thalim_pod_tax_sync_fields() as $field => $taxonomy ) { if ( ! taxonomy_exists( $taxonomy ) ) { continue; } // Valeurs du champ Pods (source de vérité) : une ligne postmeta par term_id. $ids = array_values( array_unique( array_filter( array_map( 'intval', (array) get_post_meta( $post_id, $field ) ) ) ) ); if ( empty( $ids ) ) { continue; } // Termes déjà assignés en taxonomie native. $current = wp_get_object_terms( $post_id, $taxonomy, [ 'fields' => 'ids' ] ); $current = is_wp_error( $current ) ? [] : array_map( 'intval', $current ); // N'ajouter que les manquants (append), ne jamais retirer. $missing = array_diff( $ids, $current ); if ( ! empty( $missing ) ) { wp_set_object_terms( $post_id, array_values( $missing ), $taxonomy, true ); } } }