Intuitive Custom Post Order - Version 3.1.3

Version Description

  • Added the ability to repair duplicate orders.
Download this release

Release Info

Developer hijiri
Plugin Icon 128x128 Intuitive Custom Post Order
Version 3.1.3
Comparing to
See all releases

Code changes from version 3.1.2.1 to 3.1.3

Files changed (3) hide show
  1. README.md +4 -4
  2. intuitive-custom-post-order.php +64 -2
  3. readme.txt +5 -1
README.md CHANGED
@@ -4,12 +4,12 @@
4
 
5
  ## Description
6
 
7
- Select sortable items from 'Intuitive CPO' menu of Setting menu in WordPress.
8
  Intuitively, order items( Posts, Pages, Custom Post Types, Custom Taxonomies, Sites ) using a drag and drop sortable JavaScript.
9
- Use parameters( orderby = menu_order, order = ASC ) in your theme.
10
 
11
- You can also override the auto-converted parameters( orderby and order ).
12
- ATTENTION: Only if you use 'get_posts()' to re-overwrite to the default order( orderby = date, order = DESC ), You need to use own custom parameter 'orderby = default_date'.
 
 
13
 
14
  ## Installation
15
 
4
 
5
  ## Description
6
 
 
7
  Intuitively, order items( Posts, Pages, Custom Post Types, Custom Taxonomies, Sites ) using a drag and drop sortable JavaScript.
 
8
 
9
+ Select sortable items from 'Intuitive CPO' menu of Setting menu in WordPress.
10
+
11
+ In addition, You can re-override the parameters of `orderby` and `order`, by using the `WP_Query` or `pre_get_posts` or `query_posts()` or `get_posts()`.<br>
12
+ ATTENTION: Only if you use `get_posts()` to re-overwrite to the default order( `orderby=date, order=DESC` ), You need to use own custom parameter `orderby=default_date`.
13
 
14
  ## Installation
15
 
intuitive-custom-post-order.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Intuitive Custom Post Order
4
  * Plugin URI: http://hijiriworld.com/web/plugins/intuitive-custom-post-order/
5
  * Description: Intuitively, Order Items( Posts, Pages, ,Custom Post Types, Custom Taxonomies, Sites ) using a Drag and Drop Sortable JavaScript.
6
- * Version: 3.1.2.1
7
  * Author: hijiri
8
  * Author URI: http://hijiriworld.com/web/
9
  * Text Domain: intuitive-custom-post-order
@@ -18,7 +18,7 @@
18
 
19
  define( 'HICPO_URL', plugins_url( '', __FILE__ ) );
20
  define( 'HICPO_DIR', plugin_dir_path( __FILE__ ) );
21
- define( 'HICPO_VER', '3.1.2' );
22
 
23
  /**
24
  * Uninstall hook
@@ -372,6 +372,35 @@ class Hicpo
372
  $wpdb->update( $wpdb->posts, array( 'menu_order' => $menu_order_arr[$position] ), array( 'ID' => intval( $id ) ) );
373
  }
374
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
375
  }
376
 
377
  function update_menu_order_tags()
@@ -403,6 +432,39 @@ class Hicpo
403
  $wpdb->update( $wpdb->terms, array( 'term_order' => $menu_order_arr[$position] ), array( 'term_id' => intval( $id ) ) );
404
  }
405
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
406
  }
407
 
408
  function update_menu_order_sites()
3
  * Plugin Name: Intuitive Custom Post Order
4
  * Plugin URI: http://hijiriworld.com/web/plugins/intuitive-custom-post-order/
5
  * Description: Intuitively, Order Items( Posts, Pages, ,Custom Post Types, Custom Taxonomies, Sites ) using a Drag and Drop Sortable JavaScript.
6
+ * Version: 3.1.3
7
  * Author: hijiri
8
  * Author URI: http://hijiriworld.com/web/
9
  * Text Domain: intuitive-custom-post-order
18
 
19
  define( 'HICPO_URL', plugins_url( '', __FILE__ ) );
20
  define( 'HICPO_DIR', plugin_dir_path( __FILE__ ) );
21
+ define( 'HICPO_VER', '3.1.3' );
22
 
23
  /**
24
  * Uninstall hook
372
  $wpdb->update( $wpdb->posts, array( 'menu_order' => $menu_order_arr[$position] ), array( 'ID' => intval( $id ) ) );
373
  }
374
  }
375
+
376
+ // same number check
377
+ $post_type = get_post_type($id);
378
+ $sql = "SELECT COUNT(menu_order) AS mo_count, post_type, menu_order FROM $wpdb->posts
379
+ WHERE post_type = '{$post_type}' AND post_status IN ('publish', 'pending', 'draft', 'private', 'future')
380
+ AND menu_order > 0 GROUP BY post_type, menu_order HAVING (mo_count) > 1";
381
+ $results = $wpdb->get_results( $sql );
382
+ if(count($results) > 0) {
383
+ // menu_order refresh
384
+ $sql = "SELECT ID, menu_order FROM $wpdb->posts
385
+ WHERE post_type = '{$post_type}' AND post_status IN ('publish', 'pending', 'draft', 'private', 'future')
386
+ AND menu_order > 0 ORDER BY menu_order";
387
+ $results = $wpdb->get_results( $sql );
388
+ foreach( $results as $key => $result ) {
389
+ $view_posi = array_search($result->ID, $id_arr, true);
390
+ if( $view_posi === false) {
391
+ $view_posi = 999;
392
+ }
393
+ $sort_key = ($result->menu_order * 1000) + $view_posi;
394
+ $sort_ids[$sort_key] = $result->ID;
395
+ }
396
+ ksort($sort_ids);
397
+ $oreder_no = 0;
398
+ foreach( $sort_ids as $key => $id ) {
399
+ $oreder_no = $oreder_no + 1;
400
+ $wpdb->update( $wpdb->posts, array( 'menu_order' => $oreder_no ), array( 'ID' => intval( $id ) ) );
401
+ }
402
+ }
403
+
404
  }
405
 
406
  function update_menu_order_tags()
432
  $wpdb->update( $wpdb->terms, array( 'term_order' => $menu_order_arr[$position] ), array( 'term_id' => intval( $id ) ) );
433
  }
434
  }
435
+
436
+ // same number check
437
+ $term = get_term($id);
438
+ $taxonomy = $term->taxonomy;
439
+ $sql = "SELECT COUNT(term_order) AS to_count, term_order
440
+ FROM $wpdb->terms AS terms
441
+ INNER JOIN $wpdb->term_taxonomy AS term_taxonomy ON ( terms.term_id = term_taxonomy.term_id )
442
+ WHERE term_taxonomy.taxonomy = '".$taxonomy."'GROUP BY taxonomy, term_order HAVING (to_count) > 1";
443
+ $results = $wpdb->get_results( $sql );
444
+ if(count($results) > 0) {
445
+ // term_order refresh
446
+ $sql = "SELECT terms.term_id, term_order
447
+ FROM $wpdb->terms AS terms
448
+ INNER JOIN $wpdb->term_taxonomy AS term_taxonomy ON ( terms.term_id = term_taxonomy.term_id )
449
+ WHERE term_taxonomy.taxonomy = '".$taxonomy."'
450
+ ORDER BY term_order ASC";
451
+ $results = $wpdb->get_results( $sql );
452
+ foreach( $results as $key => $result ) {
453
+ $view_posi = array_search($result->term_id, $id_arr, true);
454
+ if( $view_posi === false) {
455
+ $view_posi = 999;
456
+ }
457
+ $sort_key = ($result->term_order * 1000) + $view_posi;
458
+ $sort_ids[$sort_key] = $result->term_id;
459
+ }
460
+ ksort($sort_ids);
461
+ $oreder_no = 0;
462
+ foreach( $sort_ids as $key => $id ) {
463
+ $oreder_no = $oreder_no + 1;
464
+ $wpdb->update( $wpdb->terms, array( 'term_order' => $oreder_no ), array( 'term_id' => $id ) );
465
+ }
466
+ }
467
+
468
  }
469
 
470
  function update_menu_order_sites()
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: post order, posts order, order post, order posts, custom post type order, custom taxonomy order
5
  Requires at least: 3.5.0
6
  Tested up to: 5.5.1
7
- Stable tag: 3.1.2.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -101,6 +101,10 @@ Go to "screen options" and change "Number of items per page:".
101
 
102
  == Changelog ==
103
 
 
 
 
 
104
  = 3.1.2.1 =
105
 
106
  * Update the WordPress version this plugin was tested.
4
  Tags: post order, posts order, order post, order posts, custom post type order, custom taxonomy order
5
  Requires at least: 3.5.0
6
  Tested up to: 5.5.1
7
+ Stable tag: 3.1.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
101
 
102
  == Changelog ==
103
 
104
+ = 3.1.3 =
105
+
106
+ * Added the ability to repair duplicate orders.
107
+
108
  = 3.1.2.1 =
109
 
110
  * Update the WordPress version this plugin was tested.