Quick Edit Custom Fields with Toolset
-
I am currently working on developing a functionality that would be very helpful for my website. I would like to be able to edit the custom post fields I have created using the plugin ‘Toolset’ using the word press’s quick edit functionality. In it’s current state my code is able to correctly update the data point the exists for my custom ‘Post Order’ field. The only issue I am running into now is getting the html input box that I’ve added to the ‘Quick Edit’ form to populate with the current ‘Post Order’ data for which ever post I click the ‘Quick Edit’ button on. Currently the code pulls the data for only the page on the top row. The problem is that I need it do be able to distinguish which row I am clicking quick edit on and then populate the input field for ‘Post Order’ on the quick edit form with the post’s respective data.
I’ve attached the code I have written to this post. Any insight on how I could accomplish populating that input field based on which post is chosen for quick edit would be incredible!
Here is my ‘functions.php’ file
<?php add_post_type_support( 'page', 'excerpt' ); /* function wpdocs_theme_add_editor_styles() { add_editor_style( 'editor-style.css' ); } add_action( 'admin_init', 'wpdocs_theme_add_editor_styles' ); */ add_action('quick_edit_custom_box', 'quick_edit_fields', 10, 2); function quick_edit_fields( $column_name, $post_type){ switch ( $column_name ){ case 'wpcf-post-order': { $post_id_test = get_the_ID(); // getting the post id $order_value = get_post_meta($post_id_test,'wpcf-post-order',true); // returning custom 'Post Order' data point ?> <fieldset class='inline-edit-col-left'> <div class='inline-edit-col'> <label> <input type='number' name='order' value='<?php echo $order_value ?>'> Post Order </label> </div> </fieldset> <?php $post_id_test = NULL; break; } } } add_action('save_post', 'quick_edit_save'); function quick_edit_save($post_id){ if ( ! wp_verify_nonce( $_POST['_inline_edit'], 'inlineeditnonce')){ return; } $order = ! empty($_POST['order']) ? absint($_POST['order']) : 0; update_post_meta($post_id, 'wpcf-post-order', $order); }
Please let me know if I can provide any clarification regarding the code or my desired outcome!
- The topic ‘Quick Edit Custom Fields with Toolset’ is closed to new replies.