0

I have added a button in posts list in candidate dashboard that changes status of all posts to "offline" first, then updates the current post to "publish". I want to do this: fetch ids of all live posts only and change their status to "offline" instead of other posts with different statuses like "approved", "pending" etc. In other words only one resume can be set live.

Here is the code I am using

* Publish a CV from front-end candidate dashboard
*/
function myresumeFunction($current_post_id){

  $post_id= get_the_ID();

   //Update all post into draft status
   $live_resumes = get_post( $post_id, 'ARRAY_A' );
  
  $live_resumes ['post_status'] = 'offline';
 
 // Update the post into the database
  wp_update_post($live_resumes);


// Update Current post into live status
    $current_post = get_post( $current_post_id, 'ARRAY_A' );
    $current_post ['post_status'] = 'publish'; 
   
 // Update the post into the database
    wp_update_post($current_post);

}

// Update Current post into live status
    $current_post = get_post( $current_post_id, 'ARRAY_A' );
    $current_post ['post_status'] = 'publish'; 
   
 // Update the post into the database
    wp_update_post($current_post);

}



function cvLive(){

echo ('<form  method="POST" id="resume_live" ><input type="hidden" name="id" value="'.get_the_ID().'" /> <input type="submit"  name="set-cv-live"  id="btn-live" value="Set Live"></form>');

    
    
    
// Show a particular value.
$id = $_POST['id'];


if($id) {
myresumeFunction($id);
}
 
}

add_shortcode('make-cv-live','cvLive');



See this image of dashboard enter image description here

2
  • I have found a solution my self. Replaced this whole section //Update all post into draft status $live_resumes = get_post( $post_id, 'ARRAY_A' ); $live_resumes ['post_status'] = 'offline'; // Update the post into the database wp_update_post($live_resumes); – Hasan Cheeta Apr 8 at 15:40
  • With this $post_id= get_the_ID(); $post = get_post($post_id); //change a "Live" post to "Offline" if ( $post->post_status=='publish') { $my_post = array( 'ID' => $post_id, 'post_status' => 'offline' ); wp_update_post($my_post); } – Hasan Cheeta Apr 8 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.