• Resolved drphil9001

    (@drphil9001)


    I want to start using permalinks with my theme and ran across the following issue:

    I have a template that is used for multiple WP Pages. At the beginning of the page I cache the page id in the following manner:

    $cached_page_id = $_GET['page_id']

    for use in other functions. For example to set the sidebar based on the currently viewed page.

    With permalinks turned on and URI rewriting, the page_id is no longer in the request object.

    Is there a way to obtain the current page id when using permalinks?

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter drphil9001

    (@drphil9001)

    Of course, immediately after hitting the Send Post button I thought of the solution.

    global $wp_query;
    $cached_page_id = $wp_query->get_queried_object_id();

    sorry for the spam

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    You can also do $wp_query->get('page_id') if you want to be more specific about what variable you want.

    Thread Starter drphil9001

    (@drphil9001)

    Thanks, but that doesn’t seem to work in my situation.

    $cached_page_id = $wp_query->get('page_id');
    echo "get(page_id) = " .$cached_page_id . "<br/>;
    $cached_page_id = $wp_query->get_queried_object_id();

    results in:
    get(page_id) = 0
    get_queried_object_id() = 16

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get page id when using permalinks’ is closed to new replies.