返回介绍

remove_query_arg()

发布于 2017-09-11 10:08:57 字数 5167 浏览 1102 评论 0 收藏 0

remove_query_arg( string|array $key,  bool|string $query = false )

Removes an item or items from a query string.


description


参数

$key

(string|array) (Required) Query key or keys to remove.

$query

(bool|string) (Optional) When false uses the current URL.

Default value: false


返回值

(string) New URL query string.


源代码

File: wp-includes/functions.php

function remove_query_arg( $key, $query = false ) {
	if ( is_array( $key ) ) { // removing multiple keys
		foreach ( $key as $k )
			$query = add_query_arg( $k, false, $query );
		return $query;
	}
	return add_query_arg( $key, false, $query );
}

更新日志

Versiondescription
1.5.0Introduced.

More Information

Usage:


// individual parameter
esc_url( remove_query_arg( $key, $query ) );

// multiple parameters in an array
esc_url( remove_query_arg( array('$key1', 'key2', 'key3'), $query ) );

相关函数

Uses

  • wp-includes/functions.php: add_query_arg()

Used By

  • wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::set_return_url()
  • wp-includes/admin-bar.php: wp_admin_bar_customize_menu()
  • wp-includes/customize/class-wp-customize-theme-control.php: WP_Customize_Theme_Control::content_template()
  • wp-admin/includes/misc.php: wp_admin_canonical_url()
  • wp-admin/includes/media.php: wp_media_attach_action()
  • wp-admin/includes/theme.php: wp_prepare_themes_for_js()
  • wp-admin/includes/class-wp-list-table.php: WP_List_Table::pagination()
  • wp-admin/includes/class-wp-list-table.php: WP_List_Table::print_column_headers()
  • wp-admin/includes/misc.php: set_screen_options()
  • wp-admin/includes/dashboard.php: wp_dashboard_setup()
  • wp-admin/includes/class-walker-nav-menu-edit.php: Walker_Nav_Menu_Edit::start_el()
  • wp-admin/includes/nav-menu.php: wp_nav_menu_item_post_type_meta_box()
  • wp-admin/includes/nav-menu.php: wp_nav_menu_item_taxonomy_meta_box()
  • wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::customize_preview_settings()
  • wp-includes/functions.php: wp_nonce_ays()
  • wp-includes/link-template.php: get_pagenum_link()
  • wp-includes/media.php: wp_video_shortcode()
  • wp-includes/canonical.php: redirect_canonical()
  • wp-includes/canonical.php: _remove_qs_args_if_not_in_url()
  • wp-includes/post-formats.php: _post_format_link()
  • wp-includes/comment-template.php: get_cancel_comment_reply_link()
  • Show 16 more used by Hide more used by

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    Assuming we’re at the WordPress URL “http://www.example.com/client/?details=value1&type=value2&date=value3″…

    Note the use of esc_url() before outputting the link.

    
    // 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. When you want to manipulate a URL that is not of the page your script is in, add the targeted URL in the second parameter as below. The use of esc_url() is not required here (though encouraged), because the value is known to be safe:

    
    // 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' ) );
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文