Skip to content

Commit

Permalink
Update get_walked_pages to support custom post types Fixes 10up#200
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zachgibb authored May 9, 2024
1 parent 0b8d03d commit 1c0d38b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions class-simple-page-ordering.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public static function handle_move_under_sibling( $post_id ) {
wp_die( esc_html__( 'You are not allowed to edit this item.', 'simple-page-ordering' ) );
}

list( 'top_level_pages' => $top_level_pages, 'children_pages' => $children_pages ) = self::get_walked_pages();
list( 'top_level_pages' => $top_level_pages, 'children_pages' => $children_pages ) = self::get_walked_pages( $post->post_type );

// Get the relevant siblings.
if ( 0 === $post->post_parent ) {
Expand Down Expand Up @@ -195,9 +195,9 @@ public static function redirect_to_referer() {
* @type WP_Post[] $children_pages Children pages.
* }
*/
public static function get_walked_pages() {
public static function get_walked_pages( $post_type = 'page' ) {
global $wpdb;
$pages = get_pages( array( 'sort_column' => 'menu_order title' ) );
$pages = get_pages( array( 'sort_column' => 'menu_order title', 'post_type' => $post_type ) );

$top_level_pages = array();
$children_pages = array();
Expand Down Expand Up @@ -393,7 +393,7 @@ public static function page_row_actions( $actions, $post ) {
return $actions;
}

list( 'top_level_pages' => $top_level_pages, 'children_pages' => $children_pages ) = self::get_walked_pages();
list( 'top_level_pages' => $top_level_pages, 'children_pages' => $children_pages ) = self::get_walked_pages( $post->post_type );

$edit_link = get_edit_post_link( $post->ID, 'raw' );
$move_under_grandparent_link = add_query_arg(
Expand Down

0 comments on commit 1c0d38b

Please sign in to comment.