• Resolved dcole07

    (@dcole07)


    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);

Viewing 5 replies - 1 through 5 (of 5 total)
  • Not too sure what you mean by “add a post into the loop”, but look at Function_Reference/get_post.

    Thread Starter dcole07

    (@dcole07)

    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.

    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.

    Then you want to understand why your query has ‘nothing’.

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

    Thread Starter dcole07

    (@dcole07)

    Thanks MichaelH,

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

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Adding more posts to the loop’ is closed to new replies.