WordPress Code Snippets

A fresh mix of code snippets and tutorials

View all WP Post variables

126

Quick tip to view all WP Post variables, which can be useful for development and debugging in WordPress.

In the previously covered method of viewing all WP query variables, we display all Post variables in detail using the PHP function var_dump(). The output looks like this:

As you can see, in addition to the name and value of each variable, var_dump() also includes the type, such as “string” or “int”. If you don’t need the type information, you can simplify the results using PHP’s var_export(), like so:

echo var_export($GLOBALS['post'], TRUE);

When included in your theme template, that snippet will output a simplified version of the results returned with var_dump(). To illustrate, here is the variable output for the same page used in the previous example:

Further, here is a way to implement the display-variable technique via the theme’s functions.php file:

Of course, this can be fine-tuned by using WP’s template tags, such as conditional tags that filter by post type, category and so forth.

More tips on the way!

Learn more

Digging into WordPress