I need to get the current page id
in WordPress plugin page outside the loop. And the code I wrote for getting current page id
is in my plugin page. I tried many codes, but doesn't work
$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();
But it doesn't work for me .
global $post;
echo "pageid: ".$post->ID;
This is also not working.
When I try
global $wp_query;
$post_obj = $wp_query->get_queried_object();
$Page_ID = $post_obj->ID;
echo $Page_ID;
Then a error message appears
Fatal error: Call to a member function get_queried_object()
on a non-object in
H:xampphtdocswordpresswp-contentpluginswpkwpk.php
on line 876
When I print:
global $wp_query;
print_r($wp_query);
then result is:
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] =>
)
I don't know how to solve this, how to get the current page id
.If you know how to solve this, then I need your support. Thanks in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…