Problem:
I want to use a Toolset Form to edit the Menu Order value of posts, but I can't see a way to do this through the standard Toolset Form functionalities.
Solution:
Add a generic input to the form with the slug name the-order. Then, add custom code to the Toolset custom code section to update the Menu Order using cred_save_data action.
Sample code to get started:
add_action('cred_save_data', 'update_post_order', 10, 2);
function update_post_order($post_id, $form_data) {
// Check if the correct form is being submitted
if ($form_data['id'] == [YOUR_FORM_ID]) { // Replace [YOUR_FORM_ID] with the actual ID of your form
if (isset($_POST['the-order'])) {
$new_order = intval($_POST['the-order']); // Ensure the input is treated as an integer
// Update the post order
$args = array(
'ID' => $post_id,
'menu_order' => $new_order
);
wp_update_post($args);
}
}
}
Relevant Documentation:
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Ce sujet contient 1 reply, a 2 voices.
Dernière mise à jour par Il y a 1 years, 5 months.
Assisté par: Christopher Amirian.