Created
February 18, 2013 18:14
-
-
Save wpscholar/4979376 to your computer and use it in GitHub Desktop.
Easily reorder pages / posts in WordPress
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
<?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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
where I put this file for use it?