Obtener el ID de publicación de WordPress de la publicación actual


¿Alguien sabe cómo puedo obtener el ID de publicación de la página actual?

Entonces, si estoy en un post en particular, dentro de mi encabezado.php, quiero ser capaz de obtener el id de post actual.

Gracias!

Author: hitautodestruct, 2011-02-04

5 answers

Intenta usar esto:

$id = get_the_ID();
 45
Author: Wade Tandy,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-02-04 02:18:29

Puede usar post post->ID para el id actual.

 14
Author: borayeris,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-02-04 00:52:01

Intenta:

$post = $wp_query->post;

Luego pasa la función:

$post->ID
 8
Author: Rajnikanth,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-10-07 06:15:14
global $post;
echo $post->ID;
 6
Author: Anoop Saini,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-07-01 08:58:16

Puede obtener id a través del siguiente código...Es simple y Rápido

 <?php $post_id = get_the_ID();
   echo $post_id;
   ?>
 1
Author: Mohammad Farhan Atif Wattoo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-01-05 06:50:01