title: How to get the post data which is being published on wordpress on publish_post hook?
body: <p>I have written this code for using the post data which is being published on publish post hook but i don't know how to get values of the post</p>
  
  <pre><code>add_action('publish_post','fetch_post');
  
  function fetch_post()
  {
      global $wpdb;
      $sqlCommand = "SELECT post_title, post_name FROM wp_posts WHERE post_type='post' AND post_status='publish' ORDER BY ID DESC LIMIT 1";
      $posts = $wpdb-&gt;get_results($sqlCommand);
      print_r($posts);
  
      $sqlCommand = "INSERT INTO testing (post_title,post_name) VALUES(%s,%s)";
      $wpdb-&gt;query($wpdb-&gt;prepare($sqlCommand,$posts[0]-&gt;post_title,$posts[0]-&gt;post_name));
  }
  </code></pre>
  
  <p>This code gives me that post but when we update a post this function gets called again and it returns the last post but i want the post which is being updated or publish.</p>
  
  <p>Thanks in advance.</p>