-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
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
Add support for queryParams in gatsby-source-wordpress #10335
Conversation
Add support to specify a queryParams object on the options of gatsby-source-wordpress plugin. Query params are added to each entity request to Wordpress allowing to filter on specific fields such as lang. { ... queryParams: { lang: 'en', }, }
Add support to specify a queryParams object on the options of gatsby-source-wordpress plugin. Query params are added to each entity request to Wordpress allowing to filter on specific fields such as lang. { ... queryParams: { lang: 'en', }, }
Add support to specify a queryParams object on the options of gatsby-source-wordpress plugin. Query params are added to each entity request to Wordpress allowing to filter on specific fields such as lang. { ... queryParams: { lang: 'en', }, }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can solve issues with large websites that support multiple languages to build a site per language and use queryParams to filter per language.
Forgot to add _queryParams let _qs = url.match(/(tags|categories)/ig) ? {} : _queryParams
@@ -341,11 +346,14 @@ async function getPages( | |||
let result = [] | |||
|
|||
const getOptions = page => { | |||
// Do not filter tags & categories | |||
let qs = url.match(/(tags|categories)/ig) ? {} : _queryParams |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give context on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since tags and categories could be referenced across various posts even different languages filtering them could cause the gatsby-source-wordpress plugin to fail when it normalizes ids of tags&categories within posts and pages.
It could be updated to also be an option to decide exactly which routes queryParams should not be included on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could see language filtering not being only use case for queryParams
. It also depends on which multilanguage plugin (or even what settings of plugin) you use.
I would need to lookup what are potential use cases that users would want to use queryParams other than language filtering. What I'm thinking right now that queryParams
could accept functions:
// in gatsby-config
{
resolve: `gatsby-source-wordpress`,
options: {
[...]
queryParams: ({ url }) => url.match(/(tags|categories)/ig) ? {} : _queryParams
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed that is much more flexible.
Updated queryParams to be type of object or function returning object
Updated info regarding queryParams typeof (object | function<object>)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to support function return object
What is the status of this? Bound for release or? |
#10942 adds a similar feature but per route. |
hi, thks i need that,
getOptions take _queryParams but _queryParams is not in params.
|
@pieh Is this good to go? |
I created detailed issue about implementing this feature ( #17943 ) and will be closing this PR for now. |
Add support to specify a queryParams object on the options of gatsby-source-wordpress plugin.
Query params are added to each entity request to Wordpress allowing to filter on specific fields such as lang.