• Ok… I’m a little confused… I’ve written a plugin that I’m trying to update it on my site. Whent he page is called on its own, then it works, but if I add directories to the URL it craps out on me.

    for example:

    https://URL/photos/
    get_query_var(‘pagename’) will = “photos”

    but

    https://URL/photos/photo/234243
    get_query_var(‘pagename’) will = “” when it should equal “photos”, am I wrong?

Viewing 1 replies (of 1 total)
  • get_query_var() holds values only for the current query result. And the url photos/photo/234243 is most definitely not the “photos” Page. Also, if this is for something like an image attachment off of a Page, pagename would not be available under get_query_var().

    If I understand clearly what you’re trying to do, one thing to try is to scope $wp_query to global, access the Page parent ID this way:

    $wp_query->post->post_parent;

    Then create a new query to collect the post_name (i.e. pagename) value for that Page.

Viewing 1 replies (of 1 total)
  • The topic ‘getting the pagename’ is closed to new replies.