title: how to get post by using post id in ajax wordpress?
body: <p>I have no experience in wordpress ajax. i am trying to get my custom post type post by using post id in ajax, but i don't know how to write function.
  here is my code which i am using in functions.php</p>
  
  <pre><code>add_action('wp_ajax_data_fetch', 'data_fetch');
  add_action('wp_ajax_nopriv_data_fetch', 'data_fetch');
  function data_fetch(){
      if (isset($_POST["post_id"]) &amp;&amp; isset($_POST["post_id"]) != '') {       
        $post_id = $_POST["post_id"];
  
  
          $args = array( 'post_type' =&gt; 'sponsors');
          $the_query = new WP_Query( $post_id ); 
          if ( $the_query-&gt;have_posts() ) :
              while ( $the_query-&gt;have_posts() ) : $the_query-&gt;the_post(); ?&gt;
                          &lt;?php the_title(); ?&gt;
                      &lt;/div&gt;  
                  &lt;/div&gt;
  
              &lt;?php endwhile;
          endif;
  
      }
  
  }
  </code></pre>
  
  <p>and here is my ajax code</p>
  
  <pre><code>    &lt;a href="&lt;?php echo get_the_ID(); ?&gt;" data-id="&lt;?php echo $post-&gt;ID; ?&gt;" id="click_me" &gt;Fetch Data&lt;/a&gt;
      jQuery( document ).on( 'click', '#click_me', function() {
      var post_id = jQuery(this).data('id');
      jQuery.ajax({
          url : 'http://localhost/verturesort/wp-admin/admin-ajax.php',
          type : 'post',
          data : {
              action : 'data_fetch',
              'post_id' : post_id
          },
          success : function( response ) {
              jQuery('#datainsert').append( response );
          }
      });
  
      return false;
  });
  </code></pre>