Skip to content
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

Closed
wants to merge 10 commits into from

Conversation

u12206050
Copy link
Contributor

@u12206050 u12206050 commented Dec 6, 2018

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.

  {
    ...
    // Only get posts & pages that are english
    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',
    },
  }
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',
    },
  }
Copy link
Contributor Author

@u12206050 u12206050 left a 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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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
  }
}

Copy link
Contributor Author

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>)
Copy link
Contributor Author

@u12206050 u12206050 left a 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

@u12206050
Copy link
Contributor Author

What is the status of this? Bound for release or?

@ghost
Copy link

ghost commented Jan 21, 2019

#10942 adds a similar feature but per route.

@simonjoom
Copy link

hi, thks i need that,
i found a miss in the file fetch.js

_queryParams is not added in list of params

getOptions take _queryParams but _queryParams is not in params.

  const getOptions = page => {
   let qs = _queryParams
  if (typeof _queryParams === 'function') {
    qs = _queryParams({ url })
  }
  if (!qs || typeof qs !== 'object') qs = {}

@u12206050 u12206050 requested review from a team as code owners August 11, 2019 23:02
@sidharthachatterjee
Copy link
Contributor

@pieh Is this good to go?

@pieh
Copy link
Contributor

pieh commented Sep 27, 2019

I created detailed issue about implementing this feature ( #17943 ) and will be closing this PR for now.

@pieh pieh closed this Sep 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants