Plugin Directory

Changeset 997790


Ignore:
Timestamp:
09/27/2014 11:43:34 PM (11 years ago)
Author:
jakemgold
Message:

Fixed ordering in 4.0 due to core changes to ORDER BY in WP Query

Location:
simple-page-ordering/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • simple-page-ordering/trunk/readme.txt

    r968419 r997790  
    44Tags: order, re-order, ordering, pages, page, manage, menu_order, hierarchical, ajax, drag-and-drop, admin
    55Requires at least: 3.8
    6 Tested up to: 3.9.2
    7 Stable tag: 2.2.2
     6Tested up to: 4.0
     7Stable tag: 2.2.3
    88
    99Order your pages and other hierarchical post types with simple drag and drop right from the standard page list.
     
    7777
    7878== Changelog ==
     79
     80= 2.2.3 =
     81* Fixed ordering in WordPress 4.0 following core changes to ORDER BY in WP_Query
    7982
    8083= 2.2.2 =
  • simple-page-ordering/trunk/simple-page-ordering.php

    r968419 r997790  
    44Plugin URI: http://10up.com/plugins/simple-page-ordering-wordpress/
    55Description: Order your pages and hierarchical post types using drag and drop on the built in page list. For further instructions, open the "Help" tab on the Pages screen.
    6 Version: 2.2.2
     6Version: 2.2.3
    77Author: Jake Goldman, 10up
    88Author URI: http://10up.com
     
    8181     */
    8282    public static function wp() {
    83         if ( 0 === strpos( get_query_var('orderby'), 'menu_order' ) ) {
     83        $orderby = get_query_var('orderby');
     84        if ( ( is_string( $orderby ) && 0 === strpos( $orderby, 'menu_order' ) ) || ( isset( $orderby['menu_order'] ) && $orderby['menu_order'] == 'ASC' ) ) {
    8485            $script_name = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? 'simple-page-ordering.dev.js' : 'simple-page-ordering.js';
    8586            wp_enqueue_script( 'simple-page-ordering', plugins_url( $script_name, __FILE__ ), array('jquery-ui-sortable'), '2.1', true );
     
    120121            error_reporting( 0 );
    121122        }
     123
     124        global $wp_version;
    122125
    123126        $previd = empty( $_POST['previd'] ) ? false : (int) $_POST['previd'];
     
    157160        ));
    158161
    159         $siblings = new WP_Query(array(
     162        $siblings_query = array(
    160163            'depth'                     => 1,
    161164            'posts_per_page'            => $max_sortable_posts,
     
    163166            'post_status'               => $post_stati,
    164167            'post_parent'               => $parent_id,
    165             'orderby'                   => 'menu_order title',
    166             'order'                     => 'ASC',
     168            'orderby'                   => array( 'menu_order' => 'ASC', 'title' => 'ASC' ),
    167169            'post__not_in'              => $excluded,
    168170            'update_post_term_cache'    => false,
     
    170172            'suppress_filters'          => true,
    171173            'ignore_sticky_posts'       => true,
    172         )); // fetch all the siblings (relative ordering)
     174        );
     175        if ( version_compare( $wp_version, '4.0', '<' ) ) {
     176            $siblings_query['orderby'] = 'menu_order title';
     177            $siblings_query['order'] = 'ASC';
     178        }
     179        $siblings = new WP_Query( $siblings_query ); // fetch all the siblings (relative ordering)
    173180
    174181        // don't waste overhead of revisions on a menu order change (especially since they can't *all* be rolled back at once)
     
    275282    public static function sort_by_order_link( $views ) {
    276283        $class = ( get_query_var('orderby') == 'menu_order title' ) ? 'current' : '';
    277         $query_string = esc_url( remove_query_arg(array( 'orderby', 'order' )) );
    278         $query_string = add_query_arg( 'orderby', urlencode('menu_order title'), $query_string );
     284        $query_string = esc_url( remove_query_arg( array( 'orderby', 'order' ) ) );
     285        if ( ! is_post_type_hierarchical( get_post_type() ) ) {
     286            $query_string = add_query_arg( 'orderby', urlencode( 'menu_order title' ), $query_string );
     287            $query_string = add_query_arg( 'order', 'asc', $query_string );
     288        }
    279289        $views['byorder'] = sprintf('<a href="%s" class="%s">%s</a>', $query_string, $class, __("Sort by Order", 'simple-page-ordering'));
    280290           
Note: See TracChangeset for help on using the changeset viewer.