admin管理员组

文章数量:1122832

Is there a way I can call a link so when clicked it publishes the post via the ID I provide? I have get_delete_post_link( $postID ) set fine, and would like to do the same to make a draft go to published, or if you can't publish post, make it pending. I also have this code running in my functions.php file so may be also a way to call this if a link is clicked.

Is there a way I can call a link so when clicked it publishes the post via the ID I provide? I have get_delete_post_link( $postID ) set fine, and would like to do the same to make a draft go to published, or if you can't publish post, make it pending. I also have this code running in my functions.php file so may be also a way to call this if a link is clicked.

Share Improve this question edited Apr 13, 2017 at 12:37 CommunityBot 1 asked Feb 2, 2014 at 16:43 mancmanc 2131 gold badge3 silver badges10 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I used URL parameters and created a specific function called at init:

    add_action( 'init', 'publish_post_status' );
    function publish_post_status($post_id){
            if (isset($_GET['publish']) && current_user_can('publish_posts')) {
                    if ($_GET['publish'] == "true") {
                            $current_post = get_post( $_GET['post_id'], 'ARRAY_A' );
                            $current_post['post_status'] = 'publish';
                            wp_update_post($current_post);
                    }
            }
            if (isset($_GET['queue'])) {
                    if ($_GET['queue'] == "true") {
                            $current_post = get_post( $_GET['post_id'], 'ARRAY_A' );
                            $current_post['post_status'] = 'pending';
                            wp_update_post($current_post);
                    }
            }
    }

本文标签: Get publish post link