我正在尝试为所有返回 0 结果的产品搜索结果实现重定向到自定义 URL。使用下面的代码,我在 WordPress 中看到“
Fatal error
”消息屏幕。
这是我的代码:
add_action( 'template_redirect', 'redirect_empty_search_result', 2 );
function redirect_empty_search_result() {
if ( isset( $_GET['s'] ) && strcasecmp( $_GET['s'] ) == 0 ) {
wp_safe_redirect( '/empty-search/' );
exit();
}
}
我还没有检查你的代码,但“strcasecmp”需要两个参数 例如:
add_action( 'template_redirect', 'redirect_empty_search_result', 2 );
function redirect_empty_search_result() {
if ( isset( $_GET['s'] ) && strcasecmp( $_GET['s'], '' ) == 0 ) {
wp_safe_redirect( '/empty-search/' );
exit();
}
}