actions - Its possible to ajax update the content of the admin custom post type list

admin2025-06-02  2

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!

Share Improve this question edited Feb 23, 2019 at 20:42 Ezequiel Cattaneo asked Feb 23, 2019 at 18:19 Ezequiel CattaneoEzequiel Cattaneo 256 bronze badges 2
  • Hi... Can you upload a screenshot somewhere to see better at what you dealing with? – Brada Commented Feb 23, 2019 at 19:08
  • Added, see the "enable" checkbox column.. each one affects the status of the post in that row.. the post status change by ajax query.. and the post status change.. but the cpt list don´t refresh automatically.. i must press f5 key to reflect in the list the new post status.. or.. maybe i could only change the post title reflecting the new status "-pending" or no when the checkbox is clicked.. but not sure how to do that. – Ezequiel Cattaneo Commented Feb 23, 2019 at 20:45
Add a comment  | 

1 Answer 1

Reset to default 0

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">&nbsp;&mdash; 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">&nbsp;&mdash; 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...

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748872914a314426.html

最新回复(0)