widget reports wrong page ID (3 posts)

  1. Stephen S
    Posted 6 years ago #

    I have a really strange problem. I am trying to get the page id so that I can make a current css tag within a widget.
    As a test, I was using this code to display the path:
    $url_endpoint = get_permalink($post->ID);
    $url_endpoint = parse_url( $url_endpoint );
    $url_endpoint = $url_endpoint['path'];
    echo $url_endpoint;
    and comparing it to:

    They don't match! For some reason within the widget, the wrong page is being reported, ie the first code gives me back:
    and the second (correctly) reports that we are on:

    Any ideas?

  2. Michael
    Forum Moderator
    Posted 6 years ago #

    try to put a wp_reset_query(); before your code;

    the custom queries in the main bit of the page may distort the original $query_string; the above functions restores it.

  3. Stephen S
    Posted 6 years ago #

    Thank you, that did the trick!!!

Topic Closed

This topic has been closed to new replies.

About this Topic