Because people are often confused about how to get data from global objects/vars
使用此选项可以深入查看当前请求/wp\\U查询中可以使用的内容。
function inspect_wp_query()
{
echo \'<pre>\';
print_r($GLOBALS[\'wp_query\'])
echo \'</pre>\';
}
add_action( \'template_redirect\' ); // Query on public facing pages
add_action( \'admin_notices\' ); // Query in admin UI
顺便说一句:
// this:
global $wp_query;
$wp_query;
// is the same as
$wp_query;
// and as this:
$GLOBALS[\'wp_query\'];
// You can do this with each other global var too, like $post, etc.
How to actually get the data: // Example (not the best one)
Object WP_Query -> post stdClass -> postdata Array
// How to get the data:
// Save object into var
$my_data = new WP_Query; // on a new object
// or on the global available object from the current request
$my_data = $GLOBALS[\'wp_query\'];
// get object/stdClass
$my_post_data = $my_data->post;
// get Array
$my_post_data = $my_data[\'post\'];