Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This adds a hook to the `Simple Custom Post Order` plugin `update_menu_order()` function.
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