remove_query_arg 从URL中从移除查询字符串生成新的URL

Posted in:
Update time:2022-06-06

parameters

parametersdata typeRequired or notdescriptivedefault value
$key字符串|数组be需要移除的查询键not have
$query布尔值|字符串clogged留空时使用当前URLfalse

return value

返回值为新的 URL 字符串

usage example

假设当前页面的 URL 为:http://www.example.com/client/?details=value1&type=value2&date=value3

// 下面的示例输出 '/client/?type=value2&date=value3' 
echo esc_url( remove_query_arg( 'details' ) ); 

// 下面的示例输出 '/client/' 
$arr_params = array( 'details', 'type', 'date'); 
echo esc_url( remove_query_arg( $arr_params ) );

当我们需要操作的 URL 不是当前页面时,需要把页面 URL 添加为函数的第二个参数。

// 此示例输出 'http://www.example.com/2014/03/11/'
echo esc_url( remove_query_arg( 'details',  'http://www.example.com/2014/03/11/?details=value1' ) );
 
// 此示例输出 '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' ) );
 
// 此示例输出 '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' ) );

related function

add_query_arg

We offer WordPress Themes and Plugins Custom Development Services

This site has long undertaken WordPress themes, plugins, WooCommerce-based store mall development business. We have 10 years of experience in WordPress development, if you want to Developing Websites with WordPress, please contact WeChat: iwillhappy1314 or email: amos@wpcio.com for inquiries.

发表回复

Your email address will not be published. 必填项已用 * 标注

*