WordPress.org

Ready to get started?Download WordPress

Forums

Recursive Post Loop (2 posts)

  1. MarjoriesDaughter
    Member
    Posted 1 year ago #

    I would like to set up a page so that the post titles and excerpts from a category show with the child titles and excerpts listed after each previous level excerpt.

    Level 1 Title/Excerpt 1

    Level 1 Title/Excerpt 2
    Level 2 Title/Excerpt 1
    Level 2 Title Excerpt 2

    Level 1 Title/Excerpt 3

    etc.
    That calls for recursion, but if I understand WP_Query correctly, setting up a second WP_Query inside the first would overwrite the first. Is that true?

  2. No you can nest multiple loops and queries within each other. You just need to make sure and keep track of each of them. If you are using WP_Query use a different variable to hold the query object for each loop so nothing gets overwritten. When you finish a loop make sure you call wp_reset_postdata();

Topic Closed

This topic has been closed to new replies.

About this Topic