/* ============================================================ * 【エラー完全解消・防衛版】緊急連絡先ショートコード [emergency_list] * ============================================================ */ function custom_emergency_list_shortcode($atts) { // ショートコードの引数を安全に取得 $a = shortcode_atts( array( 'cat_id' => '', ), $atts ); $term_target = ''; // 1. 引数で明示的に cat_id が指定されている場合(最優先) if ( !empty($a['cat_id']) && intval($a['cat_id']) > 0 ) { $term_target = 'category_' . intval($a['cat_id']); } // 2. 引数がない、または 0 の場合、現在の表示画面からカテゴリーIDを「安全に」自動補完(Warning対策) else { // 現在開いている固定ページや投稿のIDを取得 $current_post_id = get_the_ID(); if ( $current_post_id ) { // 💡重要:固定ページのIDを明示的に渡して、紐づいているカテゴリーを取得します $cats = get_the_category($current_post_id); // 配列が空でなく、かつエラーがないか、[0]のオブジェクトが存在するかを厳格にチェック if ( !empty($cats) && !is_wp_error($cats) && isset($cats[0]->term_id) ) { $term_target = 'category_' . intval($cats[0]->term_id); } else { // カテゴリーが一切紐づいていない場合は、自身のページIDでフォールバック $term_target = $current_post_id; } } } // ターゲットが特定できない場合は処理を安全にスキップ(画面を壊さない) if ( empty($term_target) ) { return ''; } $order = array(1, 2, 3, 4, 5); ob_start(); // SVG定義 $svg_phone = ''; $svg_hp = ''; echo '