Catégories résolues par slug et IDs Pods par nom, tests
This commit is contained in:
@@ -62,7 +62,6 @@ class Thalim_NL_Admin_Page {
|
||||
'meta_key' => '_newsletter_month',
|
||||
'orderby' => 'meta_value',
|
||||
'order' => 'DESC',
|
||||
'lang' => '',
|
||||
]);
|
||||
$past_newsletters = array_filter($past_newsletters, function ($p) {
|
||||
return !empty(get_post_meta($p->ID, '_newsletter_month', true));
|
||||
@@ -490,15 +489,40 @@ class Thalim_NL_Admin_Page {
|
||||
|
||||
$this->do_triple_storage_category($post_id, THALIM_NL_CAT_NEWSLETTER);
|
||||
|
||||
if (function_exists('pll_set_post_language')) {
|
||||
pll_set_post_language($post_id, 'fr');
|
||||
}
|
||||
|
||||
return $post_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign a category using the Pods triple-storage pattern (same as HAL importer).
|
||||
* Résout l'ID du pod `post` et celui de son champ `categorie` par NOM
|
||||
* dans wp_posts (post_type _pods_pod / _pods_field) — les IDs en dur ne
|
||||
* survivent pas à une réimportation de base.
|
||||
*
|
||||
* @return array{0:int,1:int} [pod_id, field_id] (0 si introuvable)
|
||||
*/
|
||||
private function resolve_pods_categorie_ids(): array {
|
||||
static $ids = null;
|
||||
if ($ids === null) {
|
||||
global $wpdb;
|
||||
$pod_id = (int) $wpdb->get_var(
|
||||
"SELECT ID FROM {$wpdb->posts}
|
||||
WHERE post_type = '_pods_pod' AND post_name = 'post' LIMIT 1"
|
||||
);
|
||||
$field_id = $pod_id ? (int) $wpdb->get_var($wpdb->prepare(
|
||||
"SELECT ID FROM {$wpdb->posts}
|
||||
WHERE post_type = '_pods_field' AND post_name = 'categorie' AND post_parent = %d
|
||||
LIMIT 1",
|
||||
$pod_id
|
||||
)) : 0;
|
||||
$ids = [$pod_id, $field_id];
|
||||
}
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign a category using the Pods quadruple-storage pattern (same as HAL importer).
|
||||
*
|
||||
* ⚠ DÉPENDANCE DURE à Pods 3.x : reproduit le stockage interne de Pods
|
||||
* (postmeta + _pods_* sérialisé + wp_podsrel + catégorie WP native).
|
||||
*/
|
||||
private function do_triple_storage_category(int $post_id, int $cat_id): void {
|
||||
global $wpdb;
|
||||
@@ -513,11 +537,19 @@ class Thalim_NL_Admin_Page {
|
||||
update_post_meta($post_id, '_pods_categorie', [$cat_id]);
|
||||
|
||||
// 4. wp_podsrel row
|
||||
[$pod_id, $field_id] = $this->resolve_pods_categorie_ids();
|
||||
if (!$pod_id || !$field_id) {
|
||||
error_log(sprintf(
|
||||
'[thalim-newsletter] Pod/champ Pods "categorie" introuvable — wp_podsrel non écrit pour le post %d',
|
||||
$post_id
|
||||
));
|
||||
return;
|
||||
}
|
||||
$wpdb->delete(
|
||||
$wpdb->prefix . 'podsrel',
|
||||
[
|
||||
'pod_id' => THALIM_NL_POD_ID_POST,
|
||||
'field_id' => THALIM_NL_FIELD_ID_CAT,
|
||||
'pod_id' => $pod_id,
|
||||
'field_id' => $field_id,
|
||||
'item_id' => $post_id,
|
||||
],
|
||||
['%d', '%d', '%d']
|
||||
@@ -525,8 +557,8 @@ class Thalim_NL_Admin_Page {
|
||||
$wpdb->insert(
|
||||
$wpdb->prefix . 'podsrel',
|
||||
[
|
||||
'pod_id' => THALIM_NL_POD_ID_POST,
|
||||
'field_id' => THALIM_NL_FIELD_ID_CAT,
|
||||
'pod_id' => $pod_id,
|
||||
'field_id' => $field_id,
|
||||
'item_id' => $post_id,
|
||||
'related_pod_id' => 0,
|
||||
'related_field_id' => 0,
|
||||
@@ -617,7 +649,6 @@ class Thalim_NL_Admin_Page {
|
||||
'posts_per_page' => 1,
|
||||
'meta_key' => '_newsletter_month',
|
||||
'meta_value' => $year_month,
|
||||
'lang' => '', // Polylang: all languages
|
||||
]);
|
||||
return $posts[0] ?? null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user