Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

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);
                    }
            }
    }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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