0

I'm developing a ticketing system which already has the custom post type for the tickets with a "status" taxonomy. I have the tickets displayed in a table on the front-end and the status column has the status values in a dropdown with the current status selected by default. How can I change the status taxonomy on the back-end based on the selection of the dropdown on the front-end?

0

That would be achieved using the wp_set_post_terms function.

https://codex.wordpress.org/Function_Reference/wp_set_post_terms

You could run an ajax request on the change event of the dropdown to either wp-admin/admin-ajax.php or a custom JSON API endpoint (preferred but more work) with a payload like this

{
    new_status: 123
    post_id: 321
}

Ensure 100% that the user that is logged in has authorization to modify the post

$post = get_post( filter_var( $_POST['post_id'], FILTER_SANITIZE_NUMBER_INT ) );
if( /*Test User Auth*/ ){
    wp_set_post_terms( $post->ID, [ 
        filter_var( $_POST['new_status'], FILTER_SANITIZE_NUMBER_INT ) 
    ], 'status' );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.