get the parent ID of the current page

Support General get the parent ID of the current pageResolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #46034
    jw_blnjw_bln
    Participant

    I created a custom post type and set: Hierarchical = "YES"
    While creating a new page I set: Menu Attributes / Parent = "ABC"

    How I can now get the ID of the parent?

    Was searching the forum, or the web, or tried something like wp_get_post_parent_id( $id ).
    But I was not able to find a solution.
    Is there a MB or any other function existing to get the ID of the parent page?

    #46035
    jw_blnjw_bln
    Participant

    If not easily possible:
    Can I achieve the same using category?
    URL for parent/child = domain.com/slug/main/child
    URL for category = domain.com/category/subcategory/page
    Seems similar, or are there specific disadvantages?

    #46044
    PeterPeter
    Moderator

    Hello,

    Meta Box doesn't support a function to get the parent of the current post.

    You can use another WordPress function to get the post parent https://developer.wordpress.org/reference/functions/get_post_parent/

    or simply get the current post object and access the attribute post_parent
    https://developer.wordpress.org/reference/classes/wp_post/

    #46057
    jw_blnjw_bln
    Participant

    Ohhhh, OK (works), thanks 😉

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.