Change custom post taxonomy values from front-end

I'm developing a ticketing system which already has the custom post type for the tickets with a "status"

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

That 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

相关推荐

  • Change custom post taxonomy values from front-end

    I'm developing a ticketing system which already has the custom post type for the tickets with a "status"

    14小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信