ID < 1) { return $query_object; } $options = wbsoft_order_plugin_options(); if (is_admin()) { return false; } if ($options['auto_sort'] == "1") { $query_object->set('suppress_filters', false); } return $query_object; } /** * Add menu_order if auto sort is checked */ add_filter('posts_orderby', 'wbsoft_order_posts_orderby', 99, 2); function wbsoft_order_posts_orderby($order_by, $query_object) { global $wpdb; $options = wbsoft_order_plugin_options(); //Ignore search if($query_object->is_search()) return($order_by); if ($options['auto_sort'] == "1") $order_by = "{$wpdb->posts}.menu_order, " . $order_by; return $order_by; } add_action('admin_menu', 'wbsoft_order_add_admin_menu' ); /** * Add menu to admin section * */ function wbsoft_order_add_admin_menu() { $options = wbsoft_order_plugin_options(); //Check Current User Roles if (!current_user_can(WBSOFT_ORDER_PLUGIN_CAN_SORT)) { return; } //Add order posts section over all post types $post_types = get_post_types(); foreach( $post_types as $post_type ) { //Ignore BBPress if($post_type == 'reply' || $post_type == 'topic' || $post_type == 'forum') continue; //Add Attachment Order if($post_type == 'attachment') { add_submenu_page('upload.php', __('Custom Order', 'wbso'), __('Custom Order', 'wbso'), WBSOFT_ORDER_PLUGIN_CAN_SORT, 'custom-order-'.$post_type, 'wbsoft_order_show_order_page'); } if ($post_type == 'post') { add_submenu_page('edit.php', __('Custom Order', 'wbso'), __('Custom Order', 'wbso'), WBSOFT_ORDER_PLUGIN_CAN_SORT, 'custom-order-'.$post_type, 'wbsoft_order_show_order_page'); }else{ // if (!is_post_type_hierarchical($post_type)) add_submenu_page('edit.php?post_type='.$post_type, 'Custom Order', 'Custom Order', WBSOFT_ORDER_PLUGIN_CAN_SORT, 'custom-order-'.$post_type, 'wbsoft_order_show_order_page'); } } } function wbsoft_order_get_post_type() { $post_type = null; if ( isset($_GET['page']) && strpos($_GET['page'], 'custom-order-') !== false ) { $post_type = get_post_type_object(str_replace( 'custom-order-', '', $_GET['page'] )); } return $post_type; } function wbsoft_order_show_order_page() { $post_type = wbsoft_order_get_post_type(); ?>
0, 'show_date' => '', 'date_format' => get_option('date_format'), 'child_of' => 0, 'exclude' => '', 'title_li' => __('Pages'), 'echo' => 1, 'authors' => '', 'sort_column' => 'menu_order', 'link_before' => '', 'link_after' => '', 'walker' => '' ); $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); $output = ''; $r['exclude'] = preg_replace('/[^0-9,]/', '', $r['exclude']); $exclude_array = ( $r['exclude'] ) ? explode(',', $r['exclude']) : array(); $r['exclude'] = implode( ',', apply_filters('wp_list_pages_excludes', $exclude_array) ); // Query pages. $r['hierarchical'] = 0; $args = array( 'sort_column' => 'menu_order', 'post_type' => $post_type, 'posts_per_page' => -1, 'orderby' => 'menu_order', 'order' => 'ASC' ); if($post_type == 'attachment') $args['post_status'] = 'any'; $the_query = new WP_Query($args); $pages = $the_query->posts; if ( !empty($pages) ) { if ( $r['title_li'] ) $output .= '