I wrote this plugin code to accomplish the task of saving the order to a “pages_order” hidden plaintext field:
function enqueue_my_scripts()
{
wp_register_script('PodsHelper', plugin_dir_url(__FILE__) . 'pods-helper.js', array(), filemtime(plugin_dir_path(__FILE__) . 'pods-helper.js'), true);
wp_enqueue_script('PodsHelper');
}
global $pagenow;
if (!empty($pagenow) && 'post.php' === $pagenow) {
add_action('admin_enqueue_scripts', __NAMESPACE__ . '\enqueue_my_scripts');
}
function initObserver() {
const observer = new MutationObserver(mutations => {
let files = document.querySelectorAll('.pods-dfv-list-item');
let order = [];
for (const file of files) {
let hiddenInput = file.querySelector('input[type="hidden"]');
if (!hiddenInput) {
order = [];
break;
} else {
order.push(hiddenInput.value);
}
}
let orderString = '[' + order.join(',') + ']';
let orderInput = document.querySelector('#pods-form-ui-pods-meta-pages-order');
orderInput.value = orderString;
});
observer.observe(document.querySelector('#pods-meta-more-fields'), {
childList: true,
subtree: true
});
}
if (document.readyState === 'complete') {
initObserver();
} else {
window.addEventListener('load', function () {
initObserver();
})
}