Skip to content

Commit

Permalink
Merge pull request #203 from zachgibb/patch-1
Browse files Browse the repository at this point in the history
Update get_walked_pages to support custom post types Closes #200
  • Loading branch information
peterwilsoncc authored May 10, 2024
2 parents 0b8d03d + d7da8d8 commit 0fc5d06
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 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 @@ -190,14 +190,21 @@ public static function redirect_to_referer() {
/**
* Walk the pages and return top level and children pages.
*
* @param string $post_type Post type to walk.
*
* @return array {
* @type WP_Post[] $top_level_pages Top level pages.
* @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 +400,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 0fc5d06

Please sign in to comment.