Update get_walked_pages to support custom post types Closes #200#203
Merged
Conversation
When reordering a custom post type, this `get_walked_pages` call fails with an `undefined array key` error on line 433. Digging into it more, we can see that the `get_walked_pages` call is outputting only the `top_level_pages` for the `page` post type. This is due to the `get_pages` call on line 200 (https://github.com/10up/simple-page-ordering/blob/develop/class-simple-page-ordering.php#L200) defaulting to [`post_type => 'page'`](https://developer.wordpress.org/reference/functions/get_pages/#parameters). If we tweak this to pass in the `post_type` of the post we're working with, in the same way we do with [`is_post_type_sortable`](https://github.com/10up/simple-page-ordering/blob/develop/class-simple-page-ordering.php#L244), this issue will be resolved.
peterwilsoncc
approved these changes
May 10, 2024
Contributor
peterwilsoncc
left a comment
There was a problem hiding this comment.
This looks good to me, thank you!
To avoid delaying merge, I took the liberty of pushing a couple of commits to the pull request:
Testing with a CPT, I am able to reproduce the bug on trunk and confirm the changes to this branch resolve the issue.
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description of the Change
When reordering a custom post type, this

get_walked_pagescall fails with anundefined array keyerror on line 433.Digging into it more, we can see that the

get_walked_pagescall is outputting only thetop_level_pagesfor thepagepost type.This is due to the
get_pagescall on line 200 (https://github.com/10up/simple-page-ordering/blob/develop/class-simple-page-ordering.php#L200) defaulting topost_type => 'page'.If we tweak this to pass in the

post_typeof the post we're working with, in the same way we do withis_post_type_sortable, this issue will be resolved.Closes #200
How to test the Change
Changelog Entry
Fixed error in call to get_walked_pages for custom post types
Credits
Props @zachgibb
Checklist: