WordPress.org

Ready to get started?Download WordPress

Forums

Query Not Working (8 posts)

  1. bestcssdesigns
    Member
    Posted 5 years ago #

    Hey,

    I went to http://codex.wordpress.org/Template_Tags/query_posts and I tried using this code in my template.

    <?php
    // retrieve one post with an ID of 5
    query_posts('p=5');
    ?>

    This code did not work. I changed the ID to the ID of the post I wanted to show, and it never showed on the front page. Then when I used the following code, I got a parse error.

    <?php
    // retrieve one post with an ID of 5
    query_posts('p=5');
    
    global $more;
    // set $more to 0 in order to only get the first part of the post
    $more = 0; 
    
    // the Loop
    while (have_posts()) : the_post();
      // the content of the post
      the_content('Read the full post ยป');
    endwhile;
    ?>
  2. Shane G
    Member
    Posted 5 years ago #

    Hi,

    Use this code to retrieve the post from the post ID:

    query_posts('showposts=5');

    This will retrieve post where post ID = 5

    Thanks,

    Shane G.

  3. bestcssdesigns
    Member
    Posted 5 years ago #

    Hey Shane, I tried that.

    <?php
    // retrieve one post with an ID of 5
    query_posts('showposts=5');
    ?>

    It still did not work...

  4. Justin Tadlock
    Member
    Posted 5 years ago #

    <?php query_posts('p=5'); ?> seems to be working fine for me.

  5. bestcssdesigns
    Member
    Posted 5 years ago #

    <?php query_posts('p=5'); ?>
    Is suppose to show the content from that post on the page right?

  6. Justin Tadlock
    Member
    Posted 5 years ago #

    No, it loads the post with an ID of 5 into the query. The Loop following the query can show the post content.

  7. bestcssdesigns
    Member
    Posted 5 years ago #

    So if I want to show the post with ID 5, what code would I have to use?

  8. bestcssdesigns
    Member
    Posted 5 years ago #

    Also, will I have to insert a loop code on the page. Like what is everything I'd need to put on the page to show the title and content from a specified post?

    Like I've been looking everywhere and trying various codes. Some codes give me errors. Some simply don't show anything...

Topic Closed

This topic has been closed to new replies.

About this Topic