私は選択可能なポストカテゴリのリストから "uncategorized"を隠す必要があり、それを達成するためのコードを書いています。 この機能は、WP 4.7.5まで罰金を働いた、カテゴリが正常に隠された:なぜget_category_by_slug()がWordPress 4.8をクラッシュさせるのですか
add_filter('list_terms_exclusions', 'myproject_hide_uncategorized',1);
function myproject_hide_uncategorized($exclude_query) {
if (function_exists('get_current_screen')) {
$currentScreen = get_current_screen();
if ($currentScreen->base == 'post') {
$newquery = "";
$excluidos = array();
$excluidos[] = get_category_by_slug('sem-categoria')->cat_ID;
$excluidos[] = get_category_by_slug('uncategorized')->cat_ID;
foreach ($excluidos as $excluido) {
$newquery .= " AND t.term_id <> '$excluido' ";
}
$exclude_query .= $newquery;
}
}
return $exclude_query;
}
をしかし、それ以降のバージョン(4.8.1これまで、最新のもの)の上に、私はポストを編集しようとするたびか( `localhostの/ WP-管理/ポストnew.php」を訪問し)新しいものを作成し、私は次のようなエラーメッセージが示され得る:メモリの上限を上げる
Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 130968 bytes) in /var/www/html/wp-includes/class-wp-term-query.php on line 294
を私だけ取得タイムアウトエラーです。
:クラッシュは、これら4本の線によって引き起こされるようですが、任意のテーマのfunctions.php
ファイルのクラッシュを引き起こすように見えるに追加し、見え両方WP 4.8と4.8.1
のクリーンインストールでの挙動を再現することができ
add_filter('list_terms_exclusions', 'this_will_crash_wordpress');
function this_will_crash_wordpress($exclude_query) {
get_category_by_slug('uncategorized');
}
このエラーの原因は4.7.5の間で変更されましたか?どうすればそれを消すことができますか?コードを書き直さなければならないのですか?もしそうなら、どのように?
ようhttps://codex.wordpress.org/Function_Reference/get_term_by
はちょうど私タイムアウトエラーを取得します。 –
get_term_by();を使用してみます。 –