{"id":18482903,"date":"2025-05-25T20:14:13","date_gmt":"2025-05-25T20:14:13","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/nested-loop-or-saving-state\/"},"modified":"2025-05-25T20:14:13","modified_gmt":"2025-05-25T20:14:13","slug":"nested-loop-or-saving-state","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/nested-loop-or-saving-state\/","title":{"rendered":"Nested loop or saving state?"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I&#8217;d like to create this list of PDFs  &#8211; under the 2025 bulletins heading  &#8211; by using DisplayPosts to loop through the corresponding attachments (from the Media Library).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The issue is that the typically two or three links per Sunday are offset by a blank line before and after.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I could accomplish that either through nesting loops &#8211; <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for date = first sunday through last sunday<br \/>    for service in date.services<br \/>         &lt;print text and link for service.bulletin&gt;<br \/>    end service<br \/>end date<br \/><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">or by <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>previousSundayDate = \"xxx\"<br \/>for service = first service of the year through last service of the year<br \/>   thisSundayDate = service.SundayDate<br \/>   if previousSundayDate &lt;&gt; thisSundayDate<br \/>      &lt;print offset&gt;<br \/>   &lt;print text and link for service.bulletin&gt;<br \/>   previousSundaydate = thisSundayDate<br \/>end service<br \/>   <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">How do I accomplish either with DisplayPosts? Part of the answer may lie in <a href=\"https:\/\/displayposts.com\/2019\/01\/04\/enable-display-posts-within-post-listing\/\">https:\/\/displayposts.com\/2019\/01\/04\/enable-display-posts-within-post-listing\/<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">but the way I read that I would have to create a bunch of posts, one for each Sunday, using DisplayPosts to loop through the Bulletins for that Sunday, and then loop through the bunch of posts. Seems cumbersome, since I don&#8217;t need the individual posts, one for each Sunday.<\/p>\n","protected":false},"template":"","class_list":["post-18482903","topic","type-topic","status-publish","hentry","topic-tag-nested-loop"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18482903","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18482903\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=18482903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}