getting the pagename (2 posts)

  1. sevennine
    Posted 8 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:

    get_query_var('pagename') will = "photos"


    get_query_var('pagename') will = "" when it should equal "photos", am I wrong?

  2. Kafkaesqui

    Posted 8 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:


    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