1

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.

1 Answer 1

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);
                    }
            }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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