Support » Fixing WordPress » widget reports wrong page ID

  • 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?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Michael


    Forum Moderator

    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.

    Thank you, that did the trick!!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘widget reports wrong page ID’ is closed to new replies.