bastizim (@bastizim)

Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)

  • bastizim
    Participant

    @bastizim

    Yes, of course. Here is my script. I thought about setting menu_order for spam posts to “0” before the loop.

    <?php
    
    require_once('wp-load.php');
    
    function repair_menu_order_gaps()
    {
        global $wpdb;
    
        $posts = $wpdb->get_results("
            SELECT ID FROM $wpdb->posts
            WHERE post_type = 'topic' AND post_status = 'publish'
            ORDER BY ID ASC
        ");
        
    
        $topic_counter = 1;
        $unterschiede = 0;
    
        foreach ($posts as $post) {
    
            $poid = $post->ID;
    
            $replies  = $wpdb->get_results("
            SELECT menu_order, ID FROM $wpdb->posts
            WHERE post_type = 'reply' AND post_status = 'publish' AND post_parent=$post->ID ORDER BY menu_order ASC");
            
            $order=0;
            $counter = 0;
    
            $ids = array();
            $menu_orders = array();
            foreach ($replies as $reply) {
                $counter++;
                $order=$reply->menu_order;
                $ids[] = $reply->ID;
                $menu_orders[] = $reply->menu_order;   
            }
    
            if($counter!=$order) {
                echo "Abweichung gefunden in Post $poid: Counter $counter , Order = $order </br/>";
                $unterschiede++;
    
                $counter_rep = 0;
                foreach ($ids as $id) {
    	        $order=$menu_orders[$counter_rep];
                    $counter_rep++;
                    
    
                    echo "Neue Nummer für $id: $counter_rep (Alt: $order)<br/>";
                    
                    // Set new menu_order
                    $wpdb->update(
                        $wpdb->posts,
                        array('menu_order' => $counter_rep),
                        array('ID' => $id)
                    );
                
    
                }
            } 
    
            $topic_counter++;
        }
    

    bastizim
    Participant

    @bastizim

    I’ve just seen some replies that have the post_status spam and are responsible for gaps in some topics. The spam-marked replies are part of the menu_order.

    For example:

    ID post_status menu_order
    1 publish 1
    2 spam 2
    3 publish 3
    4 spam 4

    and so on…
    Any idea about that?


    bastizim
    Participant

    @bastizim

    Thank you, I will try that.


    bastizim
    Participant

    @bastizim

    Thanks for your reply, Robin. I have used the repair functions and the gaps are still there.

    I have installed a local test system and a script, that iterates through the replies and fix the menu_order in wp_posts of every reply with a simple counter.

    It works at the test system, but I’m not sure, if there could be any side effects.

Viewing 4 replies - 1 through 4 (of 4 total)