Nested Looper Skips Index 0 on Frontend for Penultimate Post - "$post->ID on null" Error in FrontEnd.php Line 201

Hello themeco,

I’ve encountered a critical bug with nested loopers in Cornerstone where the first iteration (index 0) of a child looper is consistently skipped on the frontend for the penultimate post in the parent looper, accompanied by a PHP error.

Environment:

  • Pro Theme/Cornerstone: 6.7.11
  • WordPress: 6.9
  • Caching: FlyingPress

Looper Structure:

  1. Grid (Looper Provider: Custom Post Type “cursussen”)
    └─ Cell (Looper Consumer)
    └─ Div (Looper Provider: {{dc:acf:post_field field=“cursusdata_jaar”}})
    └─ Text (Looper Consumer displaying year)
    └─ Div (Looper Provider: {{dc:looper:field key=“cursus_data”}})
    └─ Text (displaying dates)

The Bug:

  • Works perfectly in Cornerstone builder - all data displays for all posts
  • On frontend: For the penultimate post (second-to-last) in the parent looper:
    • Only index 1 of “cursusdata_jaar” renders
    • Index 0 is completely skipped (not in HTML source)
    • Using {{dc:looper:debug_consumer}} confirms only index 1 exists on frontend
  • All other posts (including the last post) work correctly
  • When I duplicate the problematic post, it works fine, but then the new penultimate post exhibits the same bug

PHP Error in error_log: Got error ‘PHP message: PHP Warning: Attempt to read property “ID” on null in /home/xxx/domains/xxxxxx/public_html/wp-content/themes/pro/cornerstone/includes/classes/Services/FrontEnd.php on line 201’, referer: https://sanopharm.com/cornerstone/edit/38937

Debug Findings:

  • {{dc:looper:count}} returns correct count (2) in both builder and frontend
  • Cache clearing has no effect
  • The issue is in the rendering phase, not data retrieval
  • The $post global appears to be null during nested looper execution for the penultimate item

Any idea why this is happening?

Many thanks in advance!

Dagaloni

Hey @Dagaloni,

Thanks for writing in!

I have inspected your nested Looper. You seem to have forgotten to insert a Looper Consumer for the grandchild loop:
image

The loop structure should be:

Section
  Row - Looper Provider Query Builder
     Column - Looper Consumer
         DIV - Looper Provider Dynamic Content / Looper Consumer
               DIV - Looper Provider Dynamic Content / Looper Consumer
                     Display items

Review your structure and make sure to correct the looper consumer. If needed, use {{dc:looper:field key="name" depth="2"}}. For more details about the “Depth”, check this out:

Thanks.

Hi @ruenel,

Thank you for the quick reply! I’m sorry, I don’t think I specified the looper in particular. The screenshot you sent is from the wrong looper.

I renamed the element Grid (looper bug) in section prijzen so you can easily find it.

The looper in question is working as expected except for item 3. Let me explain.

There are 4 items in the looper, each having two nested items. Item 1, 2 and 4 are displayed correctly. Only item 3 is displayed incorrectly: the first nested item is not displayed, only the second is. The weird thing is that cornerstone does display it correctly (see screenshot), only the front end is not displayed correctly.

Hey @Dagaloni,

I have simplified the looper in a test page. Everything is displayed.

Please check the demo URL in the secure note below.

I would recommend that you inspect other Loopers on the page. Something may have affected the nested loopers.

Thanks.

Hi @ruenel,

Thank you so much! I didn’t figure out what the exact issue was, but it was indeed one of the other loopers that was causing the issue.

Many thanks!

Great! Happy we could narrow it down, @Dagaloni .
Don’t hesitate to reach out if you run into any more issues.