• So i need to get the page ID that i am currently on and place it into a post query like the one below.

    <?php query_posts('p=5'); ?>

    Rather than page ID 5 its actually the page you are currently one, whatever it may be.

    Its for the purpose of multiple loops and i cannot just put a particular page id because its for a post from its archive/search results so could be anything…

Viewing 2 replies - 1 through 2 (of 2 total)
  • Could be this depending on your permalink structure:

    <?php
    $pageid = get_query_var('page_id');
    ?>

    But just put this in your page template to see all the query variables:

    <?php
    echo "<pre>"; print_r($wp_query->query_vars); echo "</pre>";
    ?>

    Though I do have the added question of why you would need to query the page you are on as WordPress would have that page in the $posts object already.

    I basically want to do the same thing; I tried

    <?php
    $pageid = get_query_var('page_id');
    ?>

    but it always returns “0”

    see below – the only thing that is unique to each of the pages I call is the actual page name.

    ‘Array
    (
    [pagename] => kaiserslautern
    [error] =>
    [m] => 0
    [p] => 0
    [post_parent] =>
    [subpost] =>
    [subpost_id] =>
    [attachment] =>
    [attachment_id] => 0
    [name] => kaiserslautern
    [hour] =>
    [static] =>
    [page_id] => 0
    [second] =>
    [minute] =>
    [day] => 0
    [monthnum] => 0
    [year] => 0
    [w] => 0
    [category_name] =>
    [tag] =>
    [cat] =>
    [tag_id] =>
    [author_name] =>
    [feed] =>
    [tb] =>
    [paged] => 0
    [comments_popup] =>
    [meta_key] =>
    [meta_value] =>
    [preview] =>
    [category__in] => Array
    (
    )

    [category__not_in] => Array
    (
    )

    [category__and] => Array
    (
    )

    [post__in] => Array
    (
    )

    [post__not_in] => Array
    (
    )

    [tag__in] => Array
    (
    )

    [tag__not_in] => Array
    (
    )

    [tag__and] => Array
    (
    )

    [tag_slug__in] => Array
    (
    )

    [tag_slug__and] => Array
    (
    )

    [caller_get_posts] =>
    [suppress_filters] =>
    [post_type] =>
    [posts_per_page] => 20
    [nopaging] =>
    [comments_per_page] => 50
    [order] => DESC
    [orderby] => wp_RAW_posts.post_date DESC
    )’

    The reason I want to do this is because depending on the page I am in I want to create a lit of child pages of the current page I’m browsing using wp_list_pages – I may be over-thinking it and there may be a simpler solution…

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Printing current page ID into query?’ is closed to new replies.