• Resolved Vig

    (@vigneshmukund)


    Hi, I’ve been using Dynamic Render extensively. However, an update to ACFE broke the feature. I’ve since managed to track down the exact issue.

    I use the Flexible content field to wrap all the sections of a page. Here’s my field group structure:
    …..
    – Flexible Content #1
    — Layout (single layout option)
    — Relationship field <— Issue
    – Flexible Content #2
    ….

    The relationship field is linked to another CPT which also has a similar structure with all content nested inside a layout within a flexible content field. My dynamic-render.php loops through the related post to fetch some values to then render it in the preview of that layout. debug.log points at an error on the line with the ??:

    $event_fields = get_field('region_event_information_section', $event->ID);
    if ($event_fields) :
    $layout = $event_fields[0]; // Get first layout
    ?? $event_title = $layout['event_title']; ??
    $venue = $layout['venue'];
    <?php endif;

    What changed? What must I change?

    Thanks for this terrific plugin!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    I’m glad to hear you enjoy ACF Extended!

    Regarding your problem, it’s hard to tell without having all the context and code structure. I suppose the warning says you cannot retrieve the $layout['event_title']?

    It looks like you have enabled the WP_DEBUG_LOG mode and you have access to the /wp-content/debug.log file, which is great! This will help you to understand where the issue come from.

    I would recommend to add some logs in your code with acf_log(). This function will write the information of your choice in the debug.log file. This will allow you to check that everything is in order.

    I would recommend the following logs:

    $event_fields = get_field('region_event_information_section', $event->ID);

    // --- logs ---
    acf_log('event id:', $event->ID);
    acf_log('event fields:', $event_fields);
    // ------------

    if ($event_fields) :
    $layout = $event_fields[0]; // Get first layout

    // --- logs ---
    acf_log('layout:', $layout);
    // ------------

    $event_title = $layout['event_title'];
    $venue = $layout['venue'];
    endif;

    Once the code is in place, refresh your WP Admin page, and check your wp-content/debug.log file again. You should see the logs and if something is wrong.

    You can read more about how to debug WordPress and ACF in our guide here, if needed.

    Let me know if you found something!

    Regards.

    Thread Starter Vig

    (@vigneshmukund)

    Thank for the quick response. Here’s my debug.log

    [06-Nov-2024 18:53:00 UTC] event id: 1022925
    [06-Nov-2024 18:53:00 UTC] event fields: Array
    (
    [0] => region_event_information_layout
    )

    [06-Nov-2024 18:53:00 UTC] layout: region_event_information_layout
    [06-Nov-2024 18:53:00 UTC] PHP Fatal error: Uncaught TypeError: Cannot access offset of type string on string in /home/nownsbeo1/domains/staging.nsbe.org/public_html/wp-content/themes/bricks-child/acf-templates/events-template/events-section-preview.php:48
    Stack trace:
    #0 /home/nownsbeo1/domains/staging.nsbe.org/public_html/wp-content/plugins/acf-extended/includes/acfe-template-functions.php(193): include()
    #1 /home/nownsbeo1/domains/staging.nsbe.org/public_html/wp-content/plugins/acf-extended/includes/fields/field-flexible-content-preview.php(485): acfe_flexible_render_layout_template()
    #2 /home/nownsbeo1/domains/staging.nsbe.org/public_html/wp-content/plugins/acf-extended/includes/fields/field-flexible-content-preview.php(353): acfe_field_flexible_content_preview->layout_preview()
    #3 /home/nownsbeo1/domains/staging.nsbe.org/public_html/wp-includes/class-wp-hook.php(324): acfe_field_flexible_content_preview->prepare_layout()
    #4 /home/nownsbeo1/domains/staging.nsbe.org/public_html/wp-includes/plugin.php(205): WP_Hook->apply_filters()
    #5 /home/nownsbeo1/domains/staging.nsbe.org/public_html/wp-content/plugins/acf-extended/includes/fields/field-flexible-content.php(565): apply_filters()
    #6 /home/nownsbeo1/domains/staging.nsbe.org/public_html/wp-content/plugins/acf-extended/includes/fields/field-flexible-content.php(395): acfe_field_flexible_content->render_layout()
    #7 /home/nownsbeo1/domains/staging.nsbe.org/public_html/wp-includes/class-wp-hook.php(324): acfe_field_flexible_content->render_field()
    #8 /home/nownsbeo1/domains/staging.nsbe.org/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()
    #9 /home/nownsbeo1/domains/staging.nsbe.org/public_html/wp-includes/plugin.php(565): WP_Hook->do_action()
    #10 /home/nownsbeo1/domains/staging.nsbe.org/public_html/wp-content/plugins/advanced-custom-fields-pro/includes/acf-hook-functions.php(113): do_action_ref_array()
    #11 /home/nownsbeo1/domains/staging.nsbe.org/public_html/wp-includes/class-wp-hook.php(324): _acf_apply_hook_variations()
    #12 /home/nownsbeo1/domains/staging.nsbe.org/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()
    #13 /home/nownsbeo1/domains/staging.nsbe.org/public_html/wp-includes/plugin.php(517): WP_Hook->do_action()
    #14 /home/nownsbeo1/domains/staging.nsbe.org/public_html/wp-content/plugins/advanced-custom-fields-pro/includes/acf-field-functions.php(807): do_action()
    #15 /home/nownsbeo1/domains/staging.nsbe.org/public_html/wp-content/plugins/advanced-custom-fields-pro/includes/acf-field-functions.php(763): acf_render_field()
    #16 /home/nownsbeo1/domains/staging.nsbe.org/public_html/wp-content/plugins/advanced-custom-fields-pro/includes/acf-field-functions.php(614): acf_render_field_wrap()
    #17 /home/nownsbeo1/domains/staging.nsbe.org/public_html/wp-content/plugins/advanced-custom-fields-pro/includes/forms/form-post.php(223): acf_render_fields()
    #18 /home/nownsbeo1/domains/staging.nsbe.org/public_html/wp-admin/includes/template.php(1456): ACF_Form_Post->render_meta_box()
    #19 /home/nownsbeo1/domains/staging.nsbe.org/public_html/wp-content/plugins/advanced-custom-fields-pro/includes/forms/form-post.php(192): do_meta_boxes()
    #20 /home/nownsbeo1/domains/staging.nsbe.org/public_html/wp-includes/class-wp-hook.php(324): ACF_Form_Post->edit_form_after_title()
    #21 /home/nownsbeo1/domains/staging.nsbe.org/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()
    #22 /home/nownsbeo1/domains/staging.nsbe.org/public_html/wp-includes/plugin.php(517): WP_Hook->do_action()
    #23 /home/nownsbeo1/domains/staging.nsbe.org/public_html/wp-admin/edit-form-advanced.php(607): do_action()
    #24 /home/nownsbeo1/domains/staging.nsbe.org/public_html/wp-admin/post.php(206): require('...')
    #25 {main}
    thrown in /home/nownsbeo1/domains/staging.nsbe.org/public_html/wp-content/themes/bricks-child/acf-templates/events-template/events-section-preview.php on line 48

    This is line #48: ? ? ? ? ? ? ? ? ? ? ? ? ? ? $event_title = $layout[‘event_title’];

    • This reply was modified 2 weeks, 5 days ago by Vig.
    Thread Starter Vig

    (@vigneshmukund)

    I managed to solve it. Your additional logs helped. The field it was fetching wasn’t the one I wanted. I renamed a bunch of fields on the back-end and did not update the php files with the new names, and went on to update plugins. So, it kept looking for a field that doesn’t exist…

    I feel stupid, but hey ????

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the details!

    Well yeah, it makes sense. In your code $layout is a string region_event_information_layout, but you try to work with it as if it was an array.

    if ($event_fields) :

    $layout = $event_fields[0];
    // $layout is: 'region_event_information_section' here

    $event_title = $layout['event_title']; // this is not possible, it's not an array

    endif

    What is the Field Type of get_field('region_event_information_section', $event->ID)?

    It currently just return some strings, see your logs. I’m not sure if that’s normal.

    [06-Nov-2024 18:53:00 UTC] event fields: Array
    (
    [0] => region_event_information_layout
    )

    I would recommend to enable the Developer Mode (see documentation), and head over your WP Admin and go edit the post 1022925. The Developer Mode will show you all the metadata saved on this post. Look for your region_event_information_section meta, you should get more information.

    Regards.

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Ah yeah, if the Field key/configuration cannot be found, it makes sense your get_field() return wrong values.

    I’m glad to hear it now works as expected!

    Have a nice day!

    Regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.