Skip to content

Instantly share code, notes, and snippets.

@wpscholar
Created February 18, 2013 18:14
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save wpscholar/4979376 to your computer and use it in GitHub Desktop.
Easily reorder pages / posts in WordPress
<?php
function reorder_posts( $order = array() ) {
global $wpdb;
$list = join(', ', $order);
$wpdb->query( 'SELECT @i:=-1' );
$result = $wpdb->query(
"UPDATE wp_posts SET menu_order = ( @i:= @i+1 )
WHERE ID IN ( $list ) ORDER BY FIELD( ID, $list );"
);
return $result;
}
@ossarotte
Copy link

where I put this file for use it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment