Last active
August 29, 2015 13:56
-
-
Save pryley/8817068 to your computer and use it in GitHub Desktop.
This adds a hook to the `Simple Custom Post Order` plugin `update_menu_order()` function.
This file contains 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
function update_menu_order() { | |
global $wpdb; | |
parse_str( $_POST['order'], $data ); | |
if ( is_array( $data ) ) { | |
$id_arr = array( ); | |
foreach ( $data as $key => $values ) { | |
foreach ( $values as $position => $id ) { | |
$id_arr[] = $id; | |
} | |
} | |
$menu_order_arr = array( ); | |
foreach ( $id_arr as $key => $id ) { | |
$results = $wpdb->get_results( "SELECT menu_order FROM $wpdb->posts WHERE ID = " . $id ); | |
foreach ( $results as $result ) { | |
$menu_order_arr[] = $result->menu_order; | |
} | |
} | |
sort( $menu_order_arr ); | |
foreach ( $data as $key => $values ) { | |
foreach ( $values as $position => $id ) { | |
$wpdb->update( $wpdb->posts, array( 'menu_order' => $menu_order_arr[$position] ), array( 'ID' => $id ) ); | |
} | |
} | |
do_action( 'scpo_update_menu_order', $data ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment