• Hi

    I have a problem with query_posts returning an empty string when trying to return a specific page.

    In my sidebar I have this;

    <div id=menu>
    <ul><?php query_posts('pageid=6'); ?></ul>
    <ul><a href="<?php query_posts('pagename=services'); ?>">Services</a></ul>

    (you can see I’ve tried it embedded within an A tag and without).

    In my html code I just get this;

    <div id=menu>
    <ul></ul>
    <ul><a href="">Services</a></ul>

    This applies to any query_posts query that I try to run in my sidebar.php. However, other queries, like a wp_list_pages query that I also run in my sidebar, run fine and return valid data.

    I’ve checked that pageid 6 exists and that there is a page with a slug of ‘services’.

    Can anyone think of why this might be ?

    Olly

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi

    You are misunderstanding what query_posts does. By itself it produces no output. It simply sets up query parameters that are then processed by running a WordPress loop. You are not running a loop so you see no output.

    You can just use wp_list_pages with a parameter that limits it to one page:

    <div id=menu>
    <ul>
      <?php wp_list_pages('include=6&amp;title_li='); ?>
    </ul>

    Thread Starter oliverm

    (@oliverm)

    AHHHH!

    Thanks very much.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘query_posts returns blank’ is closed to new replies.