/* ============================================================ * 【エラー完全解消・防衛版】緊急連絡先ショートコード [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 '
'; foreach ($order as $i) { // カテゴリー編集画面のグループデータを直接吸い出す $group = get_field("kanri-call_" . $i, $term_target); if (!$group) continue; $label = isset($group["acf_call-label_" . $i]) ? $group["acf_call-label_" . $i] : ''; $tel = isset($group["acf_call-number_" . $i]) ? $group["acf_call-number_" . $i] : ''; $url = isset($group["acf_site_url_" . $i]) ? $group["acf_site_url_" . $i] : ''; $note = isset($group["acf_call-comment_" . $i]) ? $group["acf_call-comment_" . $i] : ''; $color = isset($group["acf_buttoncolor_" . $i]) && !empty($group["acf_buttoncolor_" . $i]) ? $group["acf_buttoncolor_" . $i] : '2'; if (empty($tel) && empty($url)) continue; // アイコンとリンクの判定 if (!empty($tel)) { $link_url = 'tel:' . preg_replace('/[^0-9]/', '', $tel); $icon = $svg_phone; $display_text = $tel; } else { $link_url = esc_url($url); $icon = $svg_hp; $display_text = 'Webサイトへ'; } echo '
'; echo ''; echo '
' . $icon . '
'; echo '
'; echo '' . esc_html($label) . ''; echo '' . esc_html($display_text) . ''; echo '
'; echo '
'; if (!empty($note)) { echo '
' . wp_kses_post($note) . '
'; } echo '
'; } echo '
'; return ob_get_clean(); } add_shortcode('emergency_list', 'custom_emergency_list_shortcode');
Warning: Cannot modify header information - headers already sent by (output started at /virtual/southfront30/public_html/southfront30.shop/wp-content/themes/cocoon-child-master/inc/shortcode/emergency-list.php:1) in /virtual/southfront30/public_html/southfront30.shop/wp-content/plugins/download-monitor/src/DownloadHandler.php on line 367

Warning: Cannot modify header information - headers already sent by (output started at /virtual/southfront30/public_html/southfront30.shop/wp-content/themes/cocoon-child-master/inc/shortcode/emergency-list.php:1) in /virtual/southfront30/public_html/southfront30.shop/wp-includes/pluggable.php on line 1535

Warning: Cannot modify header information - headers already sent by (output started at /virtual/southfront30/public_html/southfront30.shop/wp-content/themes/cocoon-child-master/inc/shortcode/emergency-list.php:1) in /virtual/southfront30/public_html/southfront30.shop/wp-includes/pluggable.php on line 1538