WordPress.org

Ready to get started?Download WordPress

Forums

getting the pagename (2 posts)

  1. sevennine
    Member
    Posted 7 years ago #

    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:

    http://URL/photos/
    get_query_var('pagename') will = "photos"

    but

    http://URL/photos/photo/234243
    get_query_var('pagename') will = "" when it should equal "photos", am I wrong?

  2. Kafkaesqui

    Posted 7 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic