WordPress.org

Ready to get started?Download WordPress

Forums

widget reports wrong page ID (3 posts)

  1. Stephen S
    Member
    Posted 3 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:
    <?php
    $url_endpoint = get_permalink($post->ID);
    $url_endpoint = parse_url( $url_endpoint );
    $url_endpoint = $url_endpoint['path'];
    echo $url_endpoint;
    ?>
    and comparing it to:
    $_SERVER['REQUEST_URI']

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

    Any ideas?

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 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
    Member
    Posted 3 years ago #

    Thank you, that did the trick!!!

Topic Closed

This topic has been closed to new replies.

About this Topic