Title: Get current post ID
Last modified: February 5, 2017

---

# Get current post ID

 *  Resolved [dweb2012](https://wordpress.org/support/users/dweb2012/)
 * (@dweb2012)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/get-current-post-id-2/)
 * Hello,
 *     ```
       if( $pdfbutton_action == 'open') {
   
               $mpdf->Output();
   
             } else {
   
               global $post;
               $mpdf->Output( get_the_title( $post->ID ).'.pdf', 'D' );
   
   
       		$headers = 'From: Gedimat <test@new-pol.com>' . "\r\n";
               wp_mail ('bmytest@gmail.com', 'TEST', $post->ID , $header );
             }
       ```
   
 * get_the_title( $post->ID ) return the good title
    but when emailed $post->ID 
   is not the current post ID ! How to get the current post ID ?
 * Thank you for your help

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [dinamiko](https://wordpress.org/support/users/dinamiko/)
 * (@dinamiko)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/get-current-post-id-2/#post-8793350)
 * Hi dweb2012,
 * try saving initial $post->ID value in a variable and use that variable instead
   of $post->ID, something like this:
 *     ```
       global $post;
       $post_id = $post->ID;
       $mpdf->Output( get_the_title( $post_id ).'.pdf', 'D' );
       $headers = 'From: Gedimat <test@new-pol.com>' . "\r\n";
       wp_mail ('bmytest@gmail.com', 'TEST', $post_id , $header );
       ```
   
 * Thanks,
    Emili
    -  This reply was modified 9 years, 4 months ago by [dinamiko](https://wordpress.org/support/users/dinamiko/).
 *  Thread Starter [dweb2012](https://wordpress.org/support/users/dweb2012/)
 * (@dweb2012)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/get-current-post-id-2/#post-8793445)
 * Hello Dinamiko,
    Thank you for your reply, i used : `$pdf = get_query_var( ‘pdf’);’
   as $post_id and it is working.
 * As you can see here :
 * > [View post on imgur.com](https://imgur.com/a/WuAho)
 * I added a link to view and send the PDF as attached document from backoffice,
   it will be nice, if i can have 2 links : one link to view the PDF and another
   link to send the PDF via email.
 * Thank you
    -  This reply was modified 9 years, 4 months ago by [dweb2012](https://wordpress.org/support/users/dweb2012/).

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Get current post ID’ is closed to new replies.

 * ![](https://ps.w.org/dk-pdf/assets/icon-256x256.png?rev=3396282)
 * [DK PDF - WordPress PDF Generator](https://wordpress.org/plugins/dk-pdf/)
 * [Support Threads](https://wordpress.org/support/plugin/dk-pdf/)
 * [Active Topics](https://wordpress.org/support/plugin/dk-pdf/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/dk-pdf/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/dk-pdf/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [dweb2012](https://wordpress.org/support/users/dweb2012/)
 * Last activity: [9 years, 4 months ago](https://wordpress.org/support/topic/get-current-post-id-2/#post-8793445)
 * Status: resolved