Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After creating new post, need to reset post order #119

Open
beatricelucaci opened this issue Aug 24, 2022 · 3 comments
Open

After creating new post, need to reset post order #119

beatricelucaci opened this issue Aug 24, 2022 · 3 comments

Comments

@beatricelucaci
Copy link

I have this problem after last night upgrade MariaDB 10.5 to 10.6
After creating new post and after saving old post , i need to reset post order and update…

I downgraded MariaDB to version 10.5 and now everything works.
The plugin is not compatible with MariaDB 10.6.

https://wordpress.org/support/topic/after-creating-new-post-need-to-reset-post-order/

@alexgw
Copy link

alexgw commented Sep 15, 2023

Hi is there a plan to address this issue? We use the plugin on many sites that are being impacted by this

@sebastiencyr
Copy link

sebastiencyr commented Nov 28, 2023

I can confirm that the plugin has issues with MariaDB.

It seems that MariaDB evaluates the SELECT statement before the ORDER BY which gives an incorrect result for the subquery here in SCPO_Engine::refresh():

$wpdb->query( 'SET @row_number = 0;' );
$wpdb->query(
	"UPDATE $wpdb->posts as pt JOIN (

              SELECT ID, (@row_number:=@row_number + 1) AS `rank`
              FROM $wpdb->posts
              WHERE post_type = '$object' AND post_status IN ( 'publish', 'pending', 'draft', 'private', 'future' )
              ORDER BY menu_order ASC
            ) as pt2
            ON pt.id = pt2.id
            SET pt.menu_order = pt2.`rank`;"
);

Maybe do the subquery separate and use PHP for the row numbers for MariaDB?

////// update

I did this to fix the issue instead of simply commenting out the original and it works on both MySQL and MariaDB:

$current_orders = $wpdb->get_results( 
	$wpdb->prepare( "SELECT ID, menu_order FROM {$wpdb->posts} WHERE post_type = %s AND post_status IN ('publish', 'pending', 'draft', 'private', 'future') ORDER BY menu_order ASC", $object ) 
);

$subquery = "";

foreach ( $current_orders as $key => $current_order ) {
	if( ! $key ){
		$subquery .= $wpdb->prepare( "SELECT %s ID, %d `rank`", $current_order->ID, $key + 1 );
	}else{
		$subquery .= $wpdb->prepare( " UNION ALL SELECT %s, %d", $current_order->ID, $key + 1 );
	}
}

$wpdb->query( 'SET @row_number = 0;' );
$wpdb->query(
	"UPDATE $wpdb->posts as pt JOIN (
		$subquery
            ) as pt2
            ON pt.id = pt2.id
            SET pt.menu_order = pt2.`rank`;"
);

@alvasilakis
Copy link

Have the same issue do we know when this will be implemented ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants