WPGraphQL query menuOrder Page Attribute returns null
-
When using your plugin in combination with WPGraphQL, I can make a graphql query to sort a custom post type by their menu order and receive the following:
{ "data": { "projects": { "nodes": [ { "title": "ABC", "menuOrder": null }, { "title": "DEF", "menuOrder": 1 }, { "title": "GHI", "menuOrder": 2 }, { "title": "XYZ", "menuOrder": 3 } ] } } }The first item in the response has a menu order of ‘null’ instead of 0. Is this a bug or is this supposed to happen? I would expect 0 to be first, or for all items to be shifted so that ABC is 1, DEF is 2, GHI is 3, and XYZ is 4.
When I query for all projects particularly for a Gatsby site using WP as the headless CMS, this causes the ABC project to be very last in the response, when I actually need it to be first. If I have a limit of 3 on the query, the first project ABC will be excluded.
{ "data": { "projects": { "nodes": [ { "title": "DEF", "menuOrder": 1 }, { "title": "GHI", "menuOrder": 2 }, { "title": "XYZ", "menuOrder": 3 }, { "title": "ABC", "menuOrder": null } ] } } }
-
Posting here again with an update:
Now that it’s a new day, my graphql queries return “ABC” as the first item and is not getting excluded anymore, even though the menuOrder is still ‘null’ and if I have a limit of 3, I’ll get “ABC”, “DEF” and “GHI”.
I don’t know if its just a fluke or if another day passes and null will be at the bottom again. Having menuOrder on “ABC” as 0 feels like the right approach however, rather than ‘null’.
Null pointer (sometimes written NULL , nil , or None ), used in computer programming for an uninitialized, undefined, empty, or meaningless value.
The topic ‘WPGraphQL query menuOrder Page Attribute returns null’ is closed to new replies.