WordPress.org

Forums

[closed] How to get the Querystring ($_GET) when using Permalinks? (7 posts)

  1. d60eba
    Member
    Posted 9 years ago #

    Hi,

    I'm using WordPress 2.0.1. Using the normal link system (blog/?page_id=123 ) I can easily get to the querystring (via $_GET[page_id]).

    However, using the Permalink system (blog/2006/03/09/sample-post/) this no longer works - the entire $_GET array disappears!

    Anyone know how I can access it using Permalinks?

    Many thanks in advance,

    Leon

  2. Kafkaesqui

    Posted 9 years ago #

    The querystring for a Page under a custom permalink structure would be 'pagename'; for posts, 'name' (or 'p' if the permalink structure uses %post_id% instead of %postname%).

  3. d60eba
    Member
    Posted 9 years ago #

    Hi Kafkaesqui,

    Thanks very much, you're right the variable $pagename or $name gives me the URI for the page (eg. contact-us).

    However, what I would really like is the ID of the page (eg. 9).

    Any idea how I can get this?

    Many thanks,

    Leon

  4. katesgasis
    Member
    Posted 9 years ago #

    try $_REQUEST['page_id']

  5. Kafkaesqui

    Posted 9 years ago #

    Try this to collect the ID (should work for both Page and post):

    <?php
    global $wp_query;
    $id = $wp_query->post->ID;
    ?>

  6. d60eba
    Member
    Posted 9 years ago #

    Thanks Kafkaesqui that worked perfectly!

  7. redunzl
    Member
    Posted 9 years ago #

    $id = $wp_query->post->ID; works fine, but why does the index-page always give me the ID of the latest post? For statistics the request of the index-page is not the same as the latest post! How can I prevent this?

Topic Closed

This topic has been closed to new replies.

About this Topic