Catégories résolues par slug et IDs Pods par nom, tests
This commit is contained in:
+36
-13
@@ -19,19 +19,42 @@ define('THALIM_NL_VERSION', '1.0.0');
|
||||
define('THALIM_NL_PLUGIN_DIR', plugin_dir_path(__FILE__));
|
||||
define('THALIM_NL_PLUGIN_URL', plugin_dir_url(__FILE__));
|
||||
|
||||
// Category IDs (verified in DB 2026-03-20)
|
||||
define('THALIM_NL_CAT_APPELS', 8);
|
||||
define('THALIM_NL_CAT_COLLOQUES', 10);
|
||||
define('THALIM_NL_CAT_SEMINAIRES', 11);
|
||||
define('THALIM_NL_CAT_COMMS', 13);
|
||||
define('THALIM_NL_CAT_SOUTENANCES', 14);
|
||||
define('THALIM_NL_CAT_OUVRAGES', 15);
|
||||
define('THALIM_NL_CAT_ARTICLES', 16);
|
||||
define('THALIM_NL_CAT_NEWSLETTER', 20);
|
||||
|
||||
// Pods IDs (verified in DB 2026-03-20)
|
||||
define('THALIM_NL_POD_ID_POST', 8);
|
||||
define('THALIM_NL_FIELD_ID_CAT', 16);
|
||||
// Catégories : résolues par slug au chargement (les term_ids auto-incrémentés
|
||||
// ne survivent pas à une réimportation de base). Fallback sur les IDs
|
||||
// historiques (vérifiés en base 2026-03-20) si un slug est introuvable.
|
||||
// Une seule requête SQL, mise en cache 1 jour (transient).
|
||||
(function () {
|
||||
$cats = [
|
||||
'THALIM_NL_CAT_APPELS' => ['appels-a-contribution', 8],
|
||||
'THALIM_NL_CAT_COLLOQUES' => ['colloques-et-journees-detudes', 10],
|
||||
'THALIM_NL_CAT_SEMINAIRES' => ['seminaires', 11],
|
||||
'THALIM_NL_CAT_COMMS' => ['communications', 13],
|
||||
'THALIM_NL_CAT_SOUTENANCES' => ['soutenances', 14],
|
||||
'THALIM_NL_CAT_OUVRAGES' => ['ouvrages', 15],
|
||||
'THALIM_NL_CAT_ARTICLES' => ['articles', 16],
|
||||
'THALIM_NL_CAT_NEWSLETTER' => ['newsletter', 20],
|
||||
];
|
||||
$by_slug = get_transient('thalim_nl_cat_ids');
|
||||
if (!is_array($by_slug)) {
|
||||
global $wpdb;
|
||||
$slugs = array_column($cats, 0);
|
||||
$placeholders = implode(',', array_fill(0, count($slugs), '%s'));
|
||||
$rows = $wpdb->get_results($wpdb->prepare(
|
||||
"SELECT t.slug, t.term_id FROM {$wpdb->terms} t
|
||||
JOIN {$wpdb->term_taxonomy} tt ON tt.term_id = t.term_id
|
||||
WHERE tt.taxonomy = 'category' AND t.slug IN ($placeholders)",
|
||||
$slugs
|
||||
));
|
||||
$by_slug = [];
|
||||
foreach ((array) $rows as $row) {
|
||||
$by_slug[$row->slug] = (int) $row->term_id;
|
||||
}
|
||||
set_transient('thalim_nl_cat_ids', $by_slug, DAY_IN_SECONDS);
|
||||
}
|
||||
foreach ($cats as $const => [$slug, $fallback]) {
|
||||
define($const, $by_slug[$slug] ?? $fallback);
|
||||
}
|
||||
})();
|
||||
|
||||
/**
|
||||
* Main plugin class — singleton
|
||||
|
||||
Reference in New Issue
Block a user