Plugin Directory

Changeset 2053055


Ignore:
Timestamp:
03/19/2019 03:14:29 AM (7 years ago)
Author:
db0112358
Message:

fixed post sorting issue

Location:
content-repeater/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • content-repeater/trunk/content-repeater.php

    r2052424 r2053055  
    33 * Plugin Name: Content Repeater
    44 * Description: Quickly set up custom content like Testimonials, Coupons, Products, Flipboxes, Portals, Portfolios, Before & Afters, etc. and display it in interesting ways: Ajax Reload, Masonry, Isotope, Slick Slider, Single Row.
    5  * Version: 1.0.5
     5 * Version: 1.0.6
    66 * Author: Denis Buka
    77 * Text Domain: content-repeater
  • content-repeater/trunk/includes/sorting.php

    r2045559 r2053055  
    2020
    2121        }
     22        add_action( 'admin_init', array( 'Rptr_Sorting', 'rptr_refresh' ) );
    2223        add_action( 'pre_get_posts', array( 'Rptr_Sorting', 'rptr_pre_get_posts' ) );
    2324        add_filter( 'get_previous_post_where', array( 'Rptr_Sorting', 'rptr_previous_post_where' ) );
     
    5657                    action: 'rptr_ajax_menu_order',
    5758                    order: $('#the-list').sortable('serialize'),
    58                 }
     59                }/*,
     60                success: function(result) {
     61                    console.log(result);
     62                }*/
    5963            });
    6064        }
     
    98102        wp_die();
    99103    }
    100 
     104   
     105    public function rptr_refresh() {
     106        global $wpdb;
     107        $objects = self::rptr_sortable_objects();
     108        if (!empty($objects)) {
     109            foreach ($objects as $object) {
     110                $result = $wpdb->get_results("
     111                    SELECT count(*) as cnt, max(menu_order) as max, min(menu_order) as min
     112                    FROM $wpdb->posts
     113                    WHERE post_type = '" . $object . "' AND post_status IN ('publish', 'pending', 'draft', 'private', 'future')
     114                ");
     115
     116                if ($result[0]->cnt == 0 || $result[0]->cnt == $result[0]->max)
     117                    continue;
     118
     119                // Here's the optimization
     120                $wpdb->query("SET @row_number = 0;");
     121                $wpdb->query("UPDATE $wpdb->posts as pt JOIN (
     122                  SELECT ID, (@row_number:=@row_number + 1) AS rank
     123                  FROM $wpdb->posts
     124                  WHERE post_type = '$object' AND post_status IN ( 'publish', 'pending', 'draft', 'private', 'future' )
     125                  ORDER BY menu_order ASC
     126                ) as pt2
     127                ON pt.id = pt2.id
     128                SET pt.menu_order = pt2.rank;");
     129
     130            }
     131        }
     132    }
     133   
    101134    public function rptr_sortable_objects() {
    102135        $options = self::rptr_get_options();
  • content-repeater/trunk/readme.txt

    r2052424 r2053055  
    8383= 1.0.5 =
    8484field inserter improvements
     85= 1.0.6 =
     86fixed post sorting issue
Note: See TracChangeset for help on using the changeset viewer.