Forums

how to get the post/page ID in widget (4 posts)

  1. mercuryfenix
    Member
    Posted 2 years ago #

    What is the best way to get the page or post ID in a sidebar widget? I am trying to make sidebar widgets that do things like display a list of related file attachments for that page/post.

  2. aspepper
    Member
    Posted 2 years ago #

    Hi,

    You can use like below:

    $post_id = $GLOBALS['post']->ID;

  3. vonwa
    Member
    Posted 2 years ago #

    Very close to my need !

    I'm looking for this for category without post_id defined.

    Any solution ?

  4. MichaelH
    Volunteer
    Posted 2 years ago #

    If you are trying to display the category id for all/one category look at Function_Reference/get_categories.

    If in admin you are looking for the id see:
    How do I determine a Post, Page, Category, Tag, Link, Link Category, or User ID?

Topic Closed

This topic has been closed to new replies.

About this Topic