We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
While working on #10862 I noticed that there's no easy way to retrieve a single query argument from a variable when using the @wordpress/url package.
@wordpress/url
Since that package already uses qs, it should be trivial to add such a function.
qs
A similar PHP function is also proposed for WordPress core (https://core.trac.wordpress.org/ticket/34699), so we could get feature parity here.
The function could work like this:
import { getQueryArg } from '@wordpress/url'; const url = 'http://wp.org/wp-json/wp/v2/posts?_locale=foo'; const locale = getQueryArg( url, '_locale' ); // 'foo' const unknown = getQueryArg( url, 'foo' ); // undefined
This way one doesn't have to import qs themselves or use some indexOf or regex trickery to get a query arg or to check for its sole presence.
indexOf
Happy to work on a PR for that if such a function makes sense.
The text was updated successfully, but these errors were encountered:
As mentioned in #10862 (comment), this would make it very simple to add a hasQueryArg helper function:
hasQueryArg
function hasQueryArg( url, var ) { return typeof getQueryArg( url, var ) !== 'undefined'; }
Sorry, something went wrong.
Add some new url helper functions
f136bfb
See #10879.
Add some new url helper functions (#10885)
898f2f7
* Add some new url helper functions See #10879. * Document new functions in readme * Improve docs * Add another test for removeQueryArgs()
Add some new url helper functions (WordPress#10885)
222712e
* Add some new url helper functions See WordPress#10879. * Document new functions in readme * Improve docs * Add another test for removeQueryArgs()
No branches or pull requests
While working on #10862 I noticed that there's no easy way to retrieve a single query argument from a variable when using the
@wordpress/url
package.Since that package already uses
qs
, it should be trivial to add such a function.A similar PHP function is also proposed for WordPress core (https://core.trac.wordpress.org/ticket/34699), so we could get feature parity here.
The function could work like this:
This way one doesn't have to import
qs
themselves or use someindexOf
or regex trickery to get a query arg or to check for its sole presence.Happy to work on a PR for that if such a function makes sense.
The text was updated successfully, but these errors were encountered: