• Hi, Hope u people will be fine, i am using current code in my template file (outside the loop) to retrieve current page id.

    <?php
    // Get Current Page ID outside Loop 
    
     global $post;
    
     $PageId = $post->ID;
    
     echo $PageId;
    
     ?>

    This code is working fine in my template file. But when i use the same code in my custom widget its displaying ‘0’ instead of giving current page id. I searched a lot in wordpress forum and through Google but all in vain. If u people know how to get page id in custom widget, please let me know. Thanks in advance for your replies. Regards

Viewing 1 replies (of 1 total)
  • Thread Starter it-aroma

    (@it-aroma)

    on advise of one of my friend i’m now using the following code, following code is also working in template file but giving no result in my custom-widget or sidebar.php.

    <?php // Get Current Page ID outside Loop
    
     global $wp_query;
    
     $post_obj = $wp_query->get_queried_object();
    
     $Page_ID = $post_obj->ID;
    
     echo $Page_ID;
     ?>

    please if anybody now the problem, let me know. Thanks

Viewing 1 replies (of 1 total)
  • The topic ‘Get Current Page Id in Custom Widget not Working’ is closed to new replies.