WordPressテーマ、JIN:Rで別ブログを書いていますが、エラーが発生し、ChatGPTに聞いたら解消法を教えてくれたので備忘メモ。
起きたこと
カテゴリ一覧に表示しきれない記事数になり「もっと見る」を押すと、このようなエラーが表示されて画面崩れが。スマホだとエラー文言で画面が埋まってしまう状態に。
Warning
: Undefined array key “tag” in
/home/XXX/XXX.com/public_html/wp-content/themes/jinr/include/custom-functions.php
on line 990: Undefined array key “nowY” in
/home/XXX/XXX.com/public_html/wp-content/themes/jinr/include/custom-functions.php
on line 992: Undefined array key “nowM” in
/home/XXX/XXX.com/public_html/wp-content/themes/jinr/include/custom-functions.php
on line 993: Undefined array key “nowD” in
/home/XXX/XXX.com/public_html/wp-content/themes/jinr/include/custom-functions.php
on line 994
修正したのは
WordPress管理画面の「外観」→「テーマファイルエディター」
テーマファイル「include」の配下の「custom-functions.php」の990〜993行目
修正前
$args[‘tag’] = $_POST[‘tag’];$args[‘date_query’] = array(‘year’ => $_POST[‘nowY’],‘month’ => $_POST[‘nowM’],‘day’ => $_POST[‘nowD’]);
修正後
$args[‘tag’] = $_POST[‘tag’] ?? ”;$args[‘date_query’] = array(‘year’ => $_POST[‘nowY’] ?? null,‘month’ => $_POST[‘nowM’] ?? null,‘day’ => $_POST[‘nowD’] ?? null);