close
Skip to content

Update get_walked_pages to support custom post types Closes #200#203

Merged
peterwilsoncc merged 3 commits into
10up:developfrom
zachgibb:patch-1
May 10, 2024
Merged

Update get_walked_pages to support custom post types Closes #200#203
peterwilsoncc merged 3 commits into
10up:developfrom
zachgibb:patch-1

Conversation

@zachgibb
Copy link
Copy Markdown
Contributor

@zachgibb zachgibb commented May 9, 2024

Description of the Change

When reordering a custom post type, this get_walked_pages call fails with an undefined array key error on line 433.
Screenshot 2024-05-09 at 10 10 17 AM

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.
Screenshot 2024-05-09 at 10 16 21 AM

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'.

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, this issue will be resolved.
Screenshot 2024-05-09 at 10 22 48 AM

Closes #200

How to test the Change

  • Create a new post type
  • Create a parent and child post within this new post type
  • Verify debug warning does not get displayed

Changelog Entry

Fixed error in call to get_walked_pages for custom post types

Credits

Props @zachgibb

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

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.
@zachgibb zachgibb requested review from dkotter and jeffpaul as code owners May 9, 2024 14:28
@jeffpaul jeffpaul added this to the 2.7.1 milestone May 9, 2024
@jeffpaul jeffpaul requested review from peterwilsoncc and removed request for jeffpaul May 9, 2024 14:29
Copy link
Copy Markdown
Contributor

@peterwilsoncc peterwilsoncc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  • 520f7be A minor coding standards fix
  • d7da8d8 Addition of post type to the docblock.

Testing with a CPT, I am able to reproduce the bug on trunk and confirm the changes to this branch resolve the issue.

@peterwilsoncc peterwilsoncc merged commit 0fc5d06 into 10up:develop May 10, 2024
@zachgibb zachgibb deleted the patch-1 branch May 10, 2024 02:44
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.

PHP Warning - undefined array key class-simple-page-ordering.php 433

3 participants