Notice: Undefined offset: 0 in C:\Users\xxxxxxx\Desktop\xxxxxxx\wordpress\wp-content\plugins\auto-se
t-category\auto-set-category.php on line 35
wordpress4.4.1で以下のコードのプラグインを使用したら上記のエラーがでるようになってしまいました
これはどのように改善したらいいのでしょうか?
<?php /* Plugin Name:Auto Set Category Plugin URI:http://milkveil.com/ Description:本文中にカテゴリーと同じ文字列があった場合、そのカテゴリーをセットするプラグイン。 Version:1.0 Author:taku-k Author URI:http://milkveil.com/ */ function auto_set_category ( $post_id ) { global $post; $new_post = get_post( $post_id ); $content = $new_post->post_content; /* ループ開始 全てのカテゴリーを1つ1つ調べる */ $cat_all = get_terms( "category", "fields=all&get=all" ); foreach($cat_all as $value): /* もし本文にカテゴリーと同じ文字列があれば(デフォのカテゴリーを外してから)カテゴリーを付ける */ if ( stripos( $content, $value->name ) !== false ) { wp_remove_object_terms( $post_id, 1, 'category' ); wp_add_object_terms( $post_id, $value->name, 'category' ); } /* もし本文にカテゴリーと同じ文字列が無い時はカテゴリーを外す */ else { wp_remove_object_terms( $post_id, $value->name, 'category' ); } endforeach; /* ループ終了 全てのカテゴリーを1つ1つ調べる */ /* もしカテゴリーが1つも無かったらエラーになるからデフォのカテゴリーを付ける */ $catcheck = get_the_category($post_id); if ( is_array($catcheck) && is_null($catcheck[0]) ) { wp_add_object_terms( $post_id, 1, 'category' ); } } add_action( 'save_post', 'auto_set_category' );
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2016/01/17 01:32
退会済みユーザー
2016/01/17 01:33
2016/01/17 02:36
2016/01/17 04:31
退会済みユーザー
2016/01/17 04:34
退会済みユーザー
2016/01/17 04:47
2016/01/17 07:30
2016/01/17 12:44