Title: loop inside of loop?
Last modified: August 30, 2016

---

# loop inside of loop?

 *  Resolved [svenol](https://wordpress.org/support/users/svenol/)
 * (@svenol)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/loop-inside-of-loop/)
 * Hi Eliot,
 * Just found your plugin – it’s great and your support here is fantastic.
 * I have some issue and can’t find solution for my problem.
 * Let’s say I have 2 types of custom posts: “Projects” and “Tasks”
 * I am using ACF plugin so I have 2 groups of custom fields for each post type.
 * In task post I have field “project_name” where users can select project (existing
   post type “project”).
 * Now on front end I would like to display structrute like this:
 * 1. Project name 1
    1.1. Task name 1 1.2. Task name 2 …..
 * 2. Project name 2
    1.1. Task name 3 1.2. Task name 4 …..
 * tasks and project will be a links for post details pages.
 * Can you please help me with this?:)
 * [https://wordpress.org/plugins/custom-content-shortcode/](https://wordpress.org/plugins/custom-content-shortcode/)

Viewing 14 replies - 1 through 14 (of 14 total)

 *  Plugin Author [Eliot Akira](https://wordpress.org/support/users/miyarakira/)
 * (@miyarakira)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/loop-inside-of-loop/#post-6367279)
 * Woo, let me see.. Something like this should work:
 *     ```
       [loop type=projects fields=id]
         Project: [field title]
         [-loop type=tasks field=project_name value={ID}]
           Task: [field title]
         [/-loop]
       [/loop]
       ```
   
 * It’s using “field tags”, which are described at the bottom of the documentation
   page for loop. I pass each project’s post ID to the inner loop, to look for tasks
   whose field project_name contains that project’s ID. Hopefully that field is 
   stored as post ID.
 * Right now, there’s not a way to number them like 1, 1.1, 1.2, 2, 2.1, 2.2.. It’s
   possible to number projects using `[loop-count]`, but not the inner loop of tasks.
   If you really need them numbered like that, I can see how to solve it.
 *  Thread Starter [svenol](https://wordpress.org/support/users/svenol/)
 * (@svenol)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/loop-inside-of-loop/#post-6367281)
 * Hi Eliot,
 * Thanks for response.
 * It’s works – with some strange behaviour but i think its my fault. I need to 
   check other php code in functions.php and then will let know.
 * I don;t need numbers before task/project numer – its just example to show relations.
 *  Plugin Author [Eliot Akira](https://wordpress.org/support/users/miyarakira/)
 * (@miyarakira)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/loop-inside-of-loop/#post-6367283)
 * The formatting probably needs some work to get it to display how you want.
 * If post content auto-formatting is adding `<p>` and `<br>` tags, you can go to
   Settings and enable [raw] shortcode, then wrap the whole code block like:
 *     ```
       [raw]
         ..
       [/raw]
       ```
   
 *  Thread Starter [svenol](https://wordpress.org/support/users/svenol/)
 * (@svenol)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/loop-inside-of-loop/#post-6367289)
 * Actually [raw] shortcode couse more problems – all [field url] stop working (
   no link to post but to current page where I have shortcodes).
    When I dissabled
   raw function in your settings all return to normal
 * But the main problem to dispaly Project > task list still exist.
 * So when I created a new task, and select project (project 1) for this task then
   your shortcode display it ok (under project 1). But when I changed the project
   for this task (edit task post) for another project (project 2) your shortcode
   not dispaly this task at all (not under project 1 and project 2). But again when
   I will change settings for task from project 2 to project 1 this task will show
   under project 1.
 *  Plugin Author [Eliot Akira](https://wordpress.org/support/users/miyarakira/)
 * (@miyarakira)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/loop-inside-of-loop/#post-6367292)
 * I see, so the issue is not in the formatting.
 * Could you see if the field _project\_name_ is being saved as post ID? You could
   check in ACF field group setting, or maybe by outputting the value: `[field project_name]`.
 * You could also check if the project’s post ID is being passed correctly:
 *     ```
       [loop type=projects fields=id]
         Project: [field title] - {ID}
         ..
       [/loop]
       ```
   
 * I wonder why it works with project 1, but not project 2. Have you tried, if it
   exists, a third project to see how that works or not?
 * —
 * I just made a new update to address the issue with `[raw]`.
 *  Thread Starter [svenol](https://wordpress.org/support/users/svenol/)
 * (@svenol)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/loop-inside-of-loop/#post-6367293)
 * Hi Eliot – yes some strange situation, when I created project 3 and change post
   1 to project 3 is display under project 3. So maybe it’s works only on first (
   top/latest) project in the project loop?
 *  Plugin Author [Eliot Akira](https://wordpress.org/support/users/miyarakira/)
 * (@miyarakira)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/loop-inside-of-loop/#post-6367296)
 * Hmm..could you try a fourth one? If that works, then we can narrow it down to
   only project 2.
 *  Thread Starter [svenol](https://wordpress.org/support/users/svenol/)
 * (@svenol)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/loop-inside-of-loop/#post-6367298)
 * just created project 4 – it is on top, and the same – only project 4 display 
   tasks (projects 1,2,3 are empty)
 *  Plugin Author [Eliot Akira](https://wordpress.org/support/users/miyarakira/)
 * (@miyarakira)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/loop-inside-of-loop/#post-6367306)
 * I wonder if the right IDs are being passed. Could you tell me if the following
   shows different post IDs?
 *     ```
       [loop type=projects fields=id]
         Project: [field title] - {ID}
       [/loop]
       ```
   
 * —
 * Another angle – can you see what the following does? Where it says “1,2,3” if
   you could put the project post IDs.
 *     ```
       [loop type=tasks field=project_name value=1,2,3]
         Task: [field title]
       [/loop]
       ```
   
 *  Thread Starter [svenol](https://wordpress.org/support/users/svenol/)
 * (@svenol)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/loop-inside-of-loop/#post-6367309)
 * looks fine. test results displays:
 * TEST 1
 * Project: projekt 3 – 503
 * Project: projekt 3 – 502
 * Project: nowy projekt 2 – 495
 * Project: projekt – 492
 * TEST 2
 * Task: zadanie 2
 * Task: zadanie
 *  Thread Starter [svenol](https://wordpress.org/support/users/svenol/)
 * (@svenol)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/loop-inside-of-loop/#post-6367411)
 * Hi Eliot – did you checked plugin code if this is possible to fix?
    Thanks
 *  Plugin Author [Eliot Akira](https://wordpress.org/support/users/miyarakira/)
 * (@miyarakira)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/loop-inside-of-loop/#post-6367415)
 * I’m sorry, I’m not able to reproduce the issue so it’s difficult to know where
   to look. I’m not sure if this is an issue in the plugin, or something specific
   to your setup. I’ll create more test cases to see if I can find anything.
 *  Plugin Author [Eliot Akira](https://wordpress.org/support/users/miyarakira/)
 * (@miyarakira)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/loop-inside-of-loop/#post-6367417)
 * OK, I think I found the issue – it was related to nested loops and how their 
   internal state was being handled. Could you try the latest version and see if
   it works now?
 *  Thread Starter [svenol](https://wordpress.org/support/users/svenol/)
 * (@svenol)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/loop-inside-of-loop/#post-6367422)
 * yes thank you – it works!:)
    can you please fix [field url] after update its 
   not working

Viewing 14 replies - 1 through 14 (of 14 total)

The topic ‘loop inside of loop?’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/custom-content-shortcode_766976.svg)
 * [Custom Content Shortcode](https://wordpress.org/plugins/custom-content-shortcode/)
 * [Support Threads](https://wordpress.org/support/plugin/custom-content-shortcode/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-content-shortcode/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-content-shortcode/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-content-shortcode/reviews/)

 * 14 replies
 * 2 participants
 * Last reply from: [svenol](https://wordpress.org/support/users/svenol/)
 * Last activity: [10 years, 9 months ago](https://wordpress.org/support/topic/loop-inside-of-loop/#post-6367422)
 * Status: resolved