WP Query object cache
When I use object cache on my website (in my case, I’m on SiteGround, so I use Memcached) the plugin stops working correctly. More specifically: I reorder some posts, reload the page, and the posts are back in their original order.
As soon as I turn Memcached off, the problem is gone.
This probably happens because WP_Query caches results in object cache. And the plugin does not seem to invalidate this cache properly, see https://github.com/ColorlibHQ/simple-custom-post-order/issues/115.
For more details on the WP_Query cache implementation (which was added in WP 6.1) see https://make.wordpress.org/core/2022/10/07/improvements-to-wp_query-performance-in-6-1/.
https://wordpress.org/support/topic/wp-query-object-cache/
@beatricelucaci I had the same issue long time ago and now I headed back to it.
It seems that ColorlibHQ ist not really into fixing the issue, so I fixed it by myself. At least they provide two action hooks so you can invalidate the object cache manually when the order has changed by using the wp_cache_flush function from WordPress
add_action( 'scp_update_menu_order', 'wp_cache_flush' );
add_action( 'scp_update_menu_order_tags', 'wp_cache_flush' );
It seems to be too easy as a proper solution but it works for my case. If you had any more ideas in the past few months let me know :)
@lkaisers great input! Based on your idea, I created PR #130 to fix this in the plugin itself. Let's hope it gets accepted, that would save me from having to add your code snippet to all websites where this problem occurs 🤞🏻