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

gatsby-source-wordpress: Get menus #2426

Closed
HZSamir opened this issue Oct 12, 2017 · 17 comments
Closed

gatsby-source-wordpress: Get menus #2426

HZSamir opened this issue Oct 12, 2017 · 17 comments

Comments

@HZSamir
Copy link

HZSamir commented Oct 12, 2017

Hello again,
There was this issue discussing the manner of getting menus and their locations, with @sebastienfi suggesting to use allWordpressWpApiMenusMenusExtended, but the plugin seems to have been updated since (the docs a bit later, which was confusing) because that node no longer exists.
So my question is: Is there, at the moment, any way to fetch the menus of Worpdress? Possibly according to their location? And if not is there an ETA on this feature?

Thank you.

Edit: I have just now noticed that the docs changed. However, with WP Api Menus installed on Wordpress, and the latest Gatsby version running, I can't run the basic example of AllWordpressWpApiMenusMenuLocations. Getting the error Cannot query field \"allWordpressWpApiMenusMenusLocation\" on type \"RootQueryType\". Did you mean \"allWordpressWpApiMenusMenus\", \"wordpressWpApiMenusMenus\", or \"allWordpressWpStatuses\"?

@sebastienfi
Copy link
Contributor

Here you go

allWordpressWpApiMenusMenusItems {
    edges {
      node {
        name
        count
        items {
          order
          title
          url
          wordpress_children {
            wordpress_id
            title
            url
          }
        }
      }
    }
  }

Then, in render() :
const siteMenus = this.props.data.allWordpressWpApiMenusMenusItems.edges

Does this gives the data you expected ?

@sebastienfi
Copy link
Contributor

Closing this issue, please reopen if you feel that more information is needed :)

@dmackerman
Copy link

dmackerman commented Jun 21, 2018

It looks like the routes for the Wordpress plugin have changed?

This seems like the route for me:
/wp-json/wp-api-menus/v2/menus

I've installed the Plugin within Wordpress, but I'm getting "Cannot query field \"allWordpressWpApiMenusMenusItems\" when I try and query it.

@braco
Copy link

braco commented Sep 18, 2018

Also getting an error from the query above

{
  "errors": [
    {
      "message": "Cannot query field \"allWordpressWpApiMenusMenusItems\" on type \"Query\". Did you mean \"allWordpressWpStatuses\", \"allWordpressWpTaxonomies\", \"allWordpressGutenbergSearch\", \"allWordpressWpTypes\", or \"wordpressWpStatuses\"?",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ]
    }
  ]

edit: this was fixed by installing the correct plugin, on the right:
plugins

and removing the wordpress_children {} object from the query

@painedpineapple
Copy link

painedpineapple commented Oct 6, 2018

I'm using Version 1.3.1 of the WP API Menus plugin. It's activated, but I go into GraphiQL and there are no options for menus. I've searched but don't see anything. The other queries mentioned in this issue don't work. @braco What version where you using when you go this to work? I first installed the V2 Menus plugin, but then removed it and installed the WP API Menus. Doesn't seemed to have helped.

I should also note that the endpoints are available via the REST API, so i'm at a loss as to why I can't see the menus in GraphiQL

@painedpineapple
Copy link

painedpineapple commented Oct 6, 2018

And... hours later i run gatsby start and i'm getting all the updated endpoints. @sebastienfi is Gatsby caching this stuff somewhere and is there a way for me to clear that manually instead of waiting for it it happen? I think this is related to #8863.

@joshuaiz
Copy link

joshuaiz commented Dec 2, 2018

Having this issue as well: Gatsby 2.4.6/WP API Menus 1.3.1/WP 4.9.8

@braco's fix did not work. Also tried completely deleting the .cache directory and no change.

Here is the error:

 43:9  error  Cannot query field "allWordpressWpApiMenusMenusItems" on type "Query". Did you mean "allWordpressWpTaxonomies", "allWordpressWpUsers", "allWordpressSiteMetadata", "allWordpressWpMedia", or "wordpressWpTaxonomies"?  graphql/template-strings

It doesn't even list a suggested query param for the menu. What is the proper query parameter?

@joshuaiz
Copy link

joshuaiz commented Dec 3, 2018

@loganfromlogan and others. I found a solution - maybe this applies or can help someone else.

In your gatsby-config.js, make sure you have added menus to your included routes:

{
        resolve: 'gatsby-source-wordpress',
        options: {
        // ...
            includedRoutes: [
                '/*/*/categories',
                '/*/*/posts',
                '/*/*/pages',
                '/*/*/media',
                '/*/*/tags',
                '/*/*/taxonomies',
                '/*/*/users',
               '/*/*/menus'
          ],
       // ...
}

Without that, Gatsby doesn't query the menus at all :)

@geocine
Copy link
Contributor

geocine commented Feb 2, 2019

Thanks @braco and @joshuaiz , your combined solutions worked for me. However, we should probably move to the WP-REST-API v2 Menus , since it is the most recently update Wordpress plugin. The WP API Menus was updated 2 years ago. Also, https://github.com/postlight/headless-wp-starter uses WP-REST-API v2 Menus

@eemeeli
Copy link

eemeeli commented Apr 9, 2019

This seems to be still an issue, I don't get allWordpressWpApiMenusMenusItems{} endpoint.

Just getting allWordpressWpApiMenusMenuLocations and allWordpressWpApiMenusMenus.

Got the right version of WP-API-MENUS and the current gatsby version is 2.5.4

@paulmasek
Copy link

Same here @eemeeli. Perhaps this should be reopened?

@eemeeli
Copy link

eemeeli commented Apr 15, 2019

@paulmasek I noticed that the "problem" for me was, on the WordPress install. I didn't have default main menu on WordPress and had two custom menus. One for main language and for the secondary language. Tested with other WordPress site that had only one menu / default main menu the allWordpressWpApiMenusMenusItems appeared

@paulmasek
Copy link

@eemeeli thanks for that - much appreciated. I do have two custom menus on my wordpress instance and no default one, so perhaps the same issue is occurring for me. Surely a bug though, and a bizarre one at that :/

@arbaouimehdi
Copy link

Including /*/*menus in includedRoutes solve the problem, because before the content of includedRoutes was like that:

includedRoutes: [
  "**/categories",
  "**/posts",
  "**/pages",
  "**/events",
  "**/menu-locations/**",
  "**/media",
],

@jarrodmedrano
Copy link

Nothing has worked for me.
I tried including ///menus in my includedRoutes

@jonniebigodes
Copy link

jonniebigodes commented Jul 14, 2019

@jarrodmedrano see if this helps.

@jarrodmedrano
Copy link

Thanks. @jonniebigodes I eventually got it to work using your post. But I'm not really sure what the problem was.

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

No branches or pull requests