Hello, I am experiencing multiple problems with the ACF integration, specifically with the Object Field. I am unable to conditions for the output of my looper provider which is based on an ACF Post Object field, and the ACF integration seems to be getting stuck in a loop and breaking the frontend of the website (see end of post for PHP notices and stack trace).
First let me outline the situation… the ACF Post Object field is configured like this:
- Filter by Post Type: “work”
- Allow Null - TRUE
- Select multiple values - TRUE
- Return Format: Post Object
- This field is assigned to “Work” post type edit pages in the WP Admin
I am attempting to use this field output in my Cornerstone Single Layout template for the Work post type to display a list of related projects. But I only want the Related Projects section to display if there are Work posts that have been assigned using the above Post Object field. If no Work posts have been chosen, then the “Related Projects” section should not display, and a “Featured Work” section should display instead.
Here is my “Work - Single” layout in Cornerstone:
I have a Related Projects Section which is the looper provider, and then the Related Projects and Featured Work rows are nested.
The looper provider for the Section is based on the following Dynamic Content:
{{dc:acf:post_field field="related_projects_array"}}
The Related Projects row has the following condition set:
And the Featured Work row has the following condition set:
The problem is that these conditions do not work as expected. When the Post Object ACF field is empty (no posts have been selected) the corresponding looper provider does not resolve as “empty”.
I have also tried using the String and Number expressions as my conditions, but the field does not evaluate as 0 or an empty string using {{dc:acf:post_field field="related_projects_array"}}
. So I’m not sure how to properly setup this condition, and this is crucial to the layout properly displaying.
A workaround is to create a checkbox (true/false) field, which toggles the display of the related_projects_array Post Object field, and then using a number expression as the condition.
The above workaround works for setting element conditions, but my major concern is that the Post Object field seems to be causing problems on the backend. When developing this particular layout (the Single - Work layout) and viewing the pages on the frontend, my pages started timing out and failing to load multiple times since adding the Post Object looper provider. This usually happens when the Post Object field is empty on a given Work post (single post view).
Also, when the Post Object field is empty, the looper provider outputs the current post. I’m sure this is related to the issue somehow.
Here is the notice and stack trace from debug.log:
PHP Notice: Undefined index: return_format in /Users/colinsafranek/Local Sites/pinnacle-dev/app/public/wp-content/themes/pro/cornerstone/includes/integration/acf.php on line 247
PHP Stack trace:
PHP 1. {main}() /Users/colinsafranek/Local Sites/pinnacle-dev/app/public/index.php:0
PHP 2. require() /Users/colinsafranek/Local Sites/pinnacle-dev/app/public/index.php:17
PHP 3. wp() /Users/colinsafranek/Local Sites/pinnacle-dev/app/public/wp-blog-header.php:16
PHP 4. WP->main() /Users/colinsafranek/Local Sites/pinnacle-dev/app/public/wp-includes/functions.php:1291
PHP 5. WP->parse_request() /Users/colinsafranek/Local Sites/pinnacle-dev/app/public/wp-includes/class-wp.php:750
PHP 6. do_action_ref_array() /Users/colinsafranek/Local Sites/pinnacle-dev/app/public/wp-includes/class-wp.php:388
PHP 7. WP_Hook->do_action() /Users/colinsafranek/Local Sites/pinnacle-dev/app/public/wp-includes/plugin.php:518
PHP 8. WP_Hook->apply_filters() /Users/colinsafranek/Local Sites/pinnacle-dev/app/public/wp-includes/class-wp-hook.php:327
PHP 9. rest_api_loaded() /Users/colinsafranek/Local Sites/pinnacle-dev/app/public/wp-includes/class-wp-hook.php:303
PHP 10. WP_REST_Server->serve_request() /Users/colinsafranek/Local Sites/pinnacle-dev/app/public/wp-includes/rest-api.php:370
PHP 11. WP_REST_Server->dispatch() /Users/colinsafranek/Local Sites/pinnacle-dev/app/public/wp-includes/rest-api/class-wp-rest-server.php:414
PHP 12. WP_REST_Server->respond_to_request() /Users/colinsafranek/Local Sites/pinnacle-dev/app/public/wp-includes/rest-api/class-wp-rest-server.php:987
PHP 13. Cornerstone_Routing->data() /Users/colinsafranek/Local Sites/pinnacle-dev/app/public/wp-includes/rest-api/class-wp-rest-server.php:1140
PHP 14. apply_filters() /Users/colinsafranek/Local Sites/pinnacle-dev/app/public/wp-content/themes/pro/cornerstone/includes/classes/common/class-routing.php:72
PHP 15. WP_Hook->apply_filters() /Users/colinsafranek/Local Sites/pinnacle-dev/app/public/wp-includes/plugin.php:189
PHP 16. Cornerstone_Routing->{closure:/Users/colinsafranek/Local Sites/pinnacle-dev/app/public/wp-content/themes/pro/cornerstone/includes/classes/common/class-routing.php:120-122}() /Users/colinsafranek/Local Sites/pinnacle-dev/app/public/wp-includes/class-wp-hook.php:303
PHP 17. Cornerstone_Choices_Controller->get_dynamic_options() /Users/colinsafranek/Local Sites/pinnacle-dev/app/public/wp-content/themes/pro/cornerstone/includes/classes/common/class-routing.php:121
PHP 18. apply_filters() /Users/colinsafranek/Local Sites/pinnacle-dev/app/public/wp-content/themes/pro/cornerstone/includes/classes/controllers/class-choices-controller.php:36
PHP 19. WP_Hook->apply_filters() /Users/colinsafranek/Local Sites/pinnacle-dev/app/public/wp-includes/plugin.php:189
PHP 20. Cornerstone_Dynamic_Content_ACF->populate_option_fields() /Users/colinsafranek/Local Sites/pinnacle-dev/app/public/wp-includes/class-wp-hook.php:303
PHP 21. Cornerstone_Dynamic_Content_ACF->get_normalized_field_options() /Users/colinsafranek/Local Sites/pinnacle-dev/app/public/wp-content/themes/pro/cornerstone/includes/integration/acf.php:294
That notice is repeated about a thousand times in my debug.log file.
I also see this notice repeated:
PHP Notice: Trying to get property 'ID' of non-object in /Users/colinsafranek/Local Sites/pinnacle-dev/app/public/wp-content/themes/pro/cornerstone/includes/integration/acf.php on line 189
I will share my secure login credentials below so this can be investigated. Thank you.