获取wordpress插件页面内的当前页面ID
我需要在循环外部获取WordPress插件页面中的电流。我为获取最新信息而编写的代码位于我的插件页面中。我尝试了许多代码,但不起作用page id
page id
$page_object = get_queried_object();
$page_id = get_queried_object_id();
// "Dirty" pre 3.1
global $wp_query;
$page_object = $wp_query->get_queried_object();
$page_id = $wp_query->get_queried_object_id();
但它对我不起作用。
global $post;
echo "pageid: ".$post->ID;
这也不起作用。
当我尝试时
global $wp_query;
$post_obj = $wp_query->get_queried_object();
$Page_ID = $post_obj->ID;
echo $Page_ID;
然后出现一条错误消息
致命错误:在第 876 行的 H:\xampp\htdocs\wordpress\wp-content\plugins\wpk\wpk.php上调用非对象上的成员函数 get_queried_object()
当我打印时:
global $wp_query;
print_r($wp_query);
则结果是:
WP_Query Object
(
[query] =>
[query_vars] => Array
(
)
[tax_query] =>
[meta_query] =>
[date_query] =>
[queried_object] =>
[queried_object_id] =>
[request] =>
[posts] =>
[post_count] => 0
[current_post] => -1
[in_the_loop] =>
[post] =>
[comments] =>
[comment_count] => 0
[current_comment] => -1
[comment] =>
[found_posts] => 0
[max_num_pages] => 0
[max_num_comment_pages] => 0
[is_single] =>
[is_preview] =>
[is_page] =>
[is_archive] =>
[is_date] =>
[is_year] =>
[is_month] =>
[is_day] =>
[is_time] =>
[is_author] =>
[is_category] =>
[is_tag] =>
[is_tax] =>
[is_search] =>
[is_feed] =>
[is_comment_feed] =>
[is_trackback] =>
[is_home] =>
[is_404] =>
[is_comments_popup] =>
[is_paged] =>
[is_admin] =>
[is_attachment] =>
[is_singular] =>
[is_robots] =>
[is_posts_page] =>
[is_post_type_archive] =>
[query_vars_hash] =>
[query_vars_changed] => 1
[thumbnails_cached] =>
[stopwords:WP_Query:private] =>
)
我不知道如何解决这个问题,如何得到电流。如果你知道如何解决这个问题,那么我需要你的支持。提前致谢。page id