How to reset Post Order and show on top of the list, when change Date
When publishing a new Post, the object shows the first on the front side lists, also the first item in the Sort List. Creating further customized sorting, automatically assign an order index to the object, for a specific taxonomy term or archive. This way the Advanced Post Types Order plugin knows in what position each of the objects needs to show up when display on the front side.
Changing the post date is not affecting the item position on the lists, as containing already an order index. This is how the majority of users need and use it.
For certain sites, when changing the Post Date, the item requires to show the first on the list, as on the day of publishing. This is easy to achieve, besides changing the Post Date, the position of the item can change within the Sort List, to show accordingly on the front side.
Now, as the Post can belong to multiple taxonomies terms and multiple Sort Lists, it can be tricky and time-consuming for large websites. It can also give room for unintentional errors, in case of missing a section. Automatisation of the process is possible using a custom code.
This reset Post Order, on the object date change.
Clicking the Rest button gets the Post Date to the current timestamp.
On the backside, the following code ensures the order index reset for any post that reset.
add_action('save_post', '_custom_save_post', 10, 3 ); function _custom_save_post ( $post_ID, $post, $update ) { global $wpdb; //60 sec tolerance if ( current_time("timestamp" ) < strtotime( $post->post_date ) + 60 ) { $mysql_query = $wpdb->prepare ("DELETE FROM `". $wpdb->prefix ."apto_sort_list` WHERE object_id = %d", $post_ID ); $wpdb->get_results( $mysql_query ); } }
The above code needs inserting into a file on your /wp-content/mu-plugins/ or a custom plugin or theme functions.php.