I have a CPT list in the admin area.. and have two columns with checkboxes thats toggle the post status between publish/pending by ajax.. Is there any code or action fired by ajax to refresh the content of the CPT list without to refresh the entire page after a user clicks on one checkbox to change the status?
Thanks in advance for any kind of help!
I have a CPT list in the admin area.. and have two columns with checkboxes thats toggle the post status between publish/pending by ajax.. Is there any code or action fired by ajax to refresh the content of the CPT list without to refresh the entire page after a user clicks on one checkbox to change the status?
Thanks in advance for any kind of help!
This is a simple JavaScript problem to fix... I will tell you in pseudocode what you need to do, since I don't know what your HTML/JS/PHP code look like... If you have written the AJAX JS code then it would be easy to modify this.
I suppose you use JQuery AJAX Object abstraction... so the success function should look like:
success: function( result ) {
// Previous Code
// 1. Get the HTML Node title you want to modify
// Ex: let ctpRow = $( `#post-${post_id}` );
// 2. Get the HTML Node that contains the title
// Ex: let ctpRowTitle = ctpRow.find( '.row-title' );
if ( post has been enabled ) {
// Make sure to not have any other state.
// Ex: ctpRowTitle.find( '.post-state' ).remove();
// Append the HTML Node.
// Ex: ctpRowTitle.append( '<span class="post-state"> — Enabled</span>' );
} else {
// Make sure to not have any other state.
// Ex: ctpRowTitle.find( '.post-state' ).remove();
// Append the HTML Node.
// Ex: ctpRowTitle.append( '<span class="post-state"> — Disabled</span>' );
}
}
There are a lot more to say... I didn't understand exactly what you want to do... the classes to target the rows are from default WordPress 'Posts', so you should modify the code to match yours... this is merely an example...