Consejo rápido para ver todas las variables de WP Post, que pueden ser útiles para el desarrollo y la depuración en WordPress.
En el método previamente cubierto de ver todas las variables de consulta de WP, mostramos todas las variables de Post en detalle usando la función PHP var_dump(). La salida tiene este aspecto:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
object(WP_Post)#165 (24) { ["ID"] => int(2) ["post_author"] => string(1) "1" ["post_date"] => string(19) "2011-08-21 23:31:47" ["post_date_gmt"] => string(19) "2011-08-22 06:31:47" ["post_content"] => string(0) "" ["post_title"] => string(4) "Example Post" ["post_excerpt"] => string(0) "" ["post_status"] => string(7) "publish" ["comment_status"] => string(4) "open" ["ping_status"] => string(6) "closed" ["post_password"] => string(0) "" ["post_name"] => string(4) "example-post" ["to_ping"] => string(0) "" ["pinged"] => string(0) "" ["post_modified"] => string(19) "2021-01-20 22:11:53" ["post_modified_gmt"] => string(19) "2021-01-21 05:11:53" ["post_content_filtered"] => string(0) "" ["post_parent"] => int(0) ["guid"] => string(32) "http://example.com/wp/?page_id=2" ["menu_order"] => int(0) ["post_type"] => string(4) "page" ["post_mime_type"] => string(0) "" ["comment_count"] => string(1) "0" ["filter"] => string(3) "raw" } |
0 1 2 |
echo var_export($GLOBALS['post'], TRUE); |
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
WP_Post::__set_state( array( 'ID' => 2, 'post_author' => '1', 'post_date' => '2021-01-21 23:31:47', 'post_date_gmt' => '2021-01-22 06:31:47', 'post_content' => '', 'post_title' => 'Example Post', 'post_excerpt' => '', 'post_status' => 'publish', 'comment_status' => 'open', 'ping_status' => 'closed', 'post_password' => '', 'post_name' => 'example-post', 'to_ping' => '', 'pinged' => '', 'post_modified' => '2021-01-20 22:11:53', 'post_modified_gmt' => '2021-01-21 05:11:53', 'post_content_filtered' => '', 'post_parent' => 0, 'guid' => 'http://example.com/wp/?page_id=2', 'menu_order' => 0, 'post_type' => 'page', 'post_mime_type' => '', 'comment_count' => '0', 'filter' => 'raw', ) ) |
0 1 2 3 4 5 6 |
// View all WP Post variables function wpmix_display_globals($content) { return $content . var_export($GLOBALS['post'], TRUE); } add_filter('the_content', 'wpmix_display_globals'); |
Más consejos en camino!