WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Adding more posts to the loop (6 posts)

  1. dcole07
    Member
    Posted 5 years ago #

    When I load a particular page it has no posts, which by default is correct. However, I want to add a post into the loop before the loop is called by the template. Is there a way to do this? Something such as add($post_id);

  2. MichaelH
    Member
    Posted 5 years ago #

    Not too sure what you mean by "add a post into the loop", but look at Function_Reference/get_post.

  3. dcole07
    Member
    Posted 5 years ago #

    Most templates use if(have_posts()) : to check for posts, then use a while statement to go through all the posts by checking have_posts() and calling the_post() each time through the loop.

    The have_post() for the page I'm loading is empty, so no posts are displayed, because the query is empty. I want to insert another post into the query, so there is a post... Or if 2 posts are found, there will be 3 posts (The 2 WordPress found and the one I added.)

    I can't use get_post(), because It's important that it is done through the normal post loading method.

    Maybe I could add to $this->$posts and increase $this->$post_count, but I'm not sure how to refer to that correctly or add to it.

  4. erigami
    Member
    Posted 5 years ago #

    I'd love a way to inject a post into the loop as well. The only alternative approach that I know of is to create a fake post in the database and use the where actions to filter it out.

  5. MichaelH
    Member
    Posted 5 years ago #

    Then you want to understand why your query has 'nothing'.

    Might review the template tag, query_posts(), and The Loop.

  6. dcole07
    Member
    Posted 5 years ago #

    Thanks MichaelH,

    My problem was solved by using query_posts("cat=1&showposts=1");.

Topic Closed

This topic has been closed to new replies.

About this Topic