Warning: Trying to access array offset on false in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 216
remove_query_arg() - 从查询字符串中删除一个或多个项 - WordPress函数 - WordPress动力
当前浏览:首页 / WordPress函数 / remove_query_arg()

remove_query_arg( string|string[] $key, false|string $query = false ): string

从查询字符串中删除一个或多个项


Warning: Undefined array key -1 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 185

Warning: Undefined array key 3 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 186

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "7c76885fc5acd267cf7b90bc09e69f8f" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "11b7956772e59b3be857c87ce310e13a" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "e3bd376c8a325cae20208df4f7e3936e" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

arg

querymore...

removemore...


参数

$keystring|string[]必填
查询键或要删除的键。
$queryfalse|string可选
当为false时,使用当前URL。

默认:false


返回

string 新的URL查询字符串。



源码

查看源码 官方文档


更新日志

版本描述
1.5.0开始引入

使用示例

  • 示例1

    假设我们在WordPress URL “http://www.example.com/client/?details=value1&type=value2&date=value3〃…

    请注意在输出链接之前使用esc_url()。

    // This would output '/client/?type=value2&date=value3'
    echo esc_url( remove_query_arg( 'details' ) );
    
    // This would output '/client/'
    $arr_params = array( 'details', 'type', 'date');
    echo esc_url( remove_query_arg( $arr_params ) );
  • 示例2

    当您想要操纵不属于脚本所在页面的URL时,请在第二个参数中添加目标URL,如下所示。这里不需要使用esc_url()(尽管鼓励使用),因为已知该值是安全的:

    // This would output 'http://www.example.com/2014/03/11/'
    echo esc_url( remove_query_arg( 'details',  'http://www.example.com/2014/03/11/?details=value1' ) );
    
    // This would output 'http://www.example.com/2014/03/11/?type=value2&date=value3'
    echo esc_url( remove_query_arg( 'details',  'http://www.example.com/2014/03/11/?details=value1&type=value2&date=value3' ) );
    
    // This would output 'http://www.example.com/2014/03/11/'
    $arr_params = array( 'details', 'type', 'date');
    echo esc_url( remove_query_arg( $arr_params, 'http://www.example.com/2014/03/11/?details=value1&type=value2&date=value3' ) );