WordPress.org

Forums

[resolved] Getting the ID of external pages and display in loop or store in variable (2 posts)

  1. shagen
    Member
    Posted 2 years ago #

    I am creating a side bar navigation on a site that is pulling all the children of a page and displaying data from the posts as well as custom fields. I need to grab the ID of each of these pages and then store it in a variable so I can call the custom fields from each page. It does not matter I don't think but I am using the Advanced Custom Fields (ACF) plugin. If I can just get each page to even display each individual page ID I can then store that in a variable and I would be off and running.

    I have tried using get_the_id() in the loop but for some reason it is only grabbing and then duplicating the ID of the page I am on as I am on one of the said sub pages.

    Have a look at the code in the following pastebin... http://pastebin.com/SBMjDTJY

    I think the line of code that is giving me the trouble is probably 8 and 9. Line 6 is just a test line to see what ID is being spit out in that particular loop.

    Thanks for any time and effort spent on this.

  2. shagen
    Member
    Posted 2 years ago #

    I think I figured it out. Instead of using the get_the_ID() bit of code I was looking around and trying things and tried the following within the loop instead and I have achieved the intended result.

    $page->ID;

Topic Closed

This topic has been closed to new replies.

About this Topic