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?
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?
Share Improve this question asked Jun 4, 2019 at 20:18 Creative CacheCreative Cache 34 bronze badges1 Answer
Reset to default 0That would be achieved using the wp_set_post_terms
function.
https://codex.wordpress/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' );
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745437680a4627683.html
评论列表(0条)