Home Forums General Issues PHP errors with ACF text fields


PHP errors with ACF text fields

  • I’ve been struggling to find a solution to the below error. I’ve been in contact with Elementor pro developers but they’re unable to help, as I’ve created some custom shortcode functions (in functions.php) which is outside their support scope ?

    PHP 8.1
    Wordpress 6.3.1
    Elementor Pro 3.15.1
    ACF Pro 6.2.0

    [01-Sep-2023 02:54:06 UTC] PHP Warning:  Undefined array key 1 in /home/.../public_html/wp-content/plugins/elementor-pro/modules/dynamic-tags/acf/tags/acf-text.php on line 33
    [01-Sep-2023 02:54:06 UTC] PHP Warning:  Undefined array key 0 in /home/.../public_html/wp-content/plugins/elementor-pro/modules/dynamic-tags/acf/tags/acf-text.php on line 33 

    Firstly – all of the pages that use ACF and my custom queries/shortcodes all work as expected. The problem is that these errors are being generated evry few seconds so the log file grows exponentially over a few hours.

    I have several ACF text fields – some are used in repeater fields and others are not. They are all edited via 2 options pages.

    Our homepage uses a post loop that contains editor and author info that includes an ACF text field (not part of a repeater) guest_author

    Code for homepage Guest Author:

    function custom_author($post_id) {
           global $post_id;		
    if(is_front_page() || is_post_type_archive() && (get_field( 'guest_author', $post_id ) != "")){
    	   $author_value = get_field( 'guest_author', $post_id );	    
    	   return ( '<span style="color:#000;">By: </span><span style="color:#f70d28;">'.$author_value.'</span><br>');
    	 // }
    	} 	else {
    	        $author_id = get_the_author_meta( 'ID' );
    	  		$author_value = get_the_author_meta('display_name', $author_id);
    		return $author_value;
    add_filter('the_author', 'custom_author', 10, 2); 

    My repeater fields are a simple format that output rows with text and href as below:-

    function voicepage_elementor_shortcode_resources( ) {
         if (have_rows( 'voice_resources', 'voice_options' )):
    		while (have_rows( 'voice_resources', 'voice_options' )): the_row();
    	        $restext = get_sub_field('field_64b5d8fc89d87'); // Also works using the field name resource_title in place of field key
    		$reslink = get_sub_field('field_64b5d91589d88'); // Resource link - name or key works
            echo '<div class="resourcelist"><div class="resourcetext"><p><a href="'.$reslink.'">'.$restext.'</a></p></div><div class="resourceicon"><i class="far fa-arrow-alt-circle-right"></i></div></div>';
    add_shortcode( 'voice_resources_output', 'voicepage_elementor_shortcode_resources'); 

    Really appreciate any directions I should take to get rid of these errors, apart from turning them off.


  • I don’t see anything in the code you provided that should be causing this.

    The error is in an Elementor function that is trying to get the value of a custom field. This function would only be called when using the dynamic content setting and entering a field name. It would not be caused by using a shortcode.

  • Thanks for that info John.

    I just changed over a custom field in my homepage post loop from using elementor dynamic content -> changed to a shortcode but that rendered the homepage uneditable in elementor so definitely something going on there.

    Will keep trying to find the culprit…

  • This below custom query gives me a critical page error using an ACF post object set to post ID. I’m beginning to think Elementor queries using ACF are broken, at least with my WordPress install. I’ve ran troubleshooting mode and with all plugins active the Elementor editor page loads but only when this code is commented out.

    add_action( 'elementor/query/voicesponsored_filter_2', function ( $query ) { 
    $voicesponsored_link = get_field( 'voice_sponsored_2', 'voice_options');
    $query->set( 'p',$voicesponsored_link);
    } );
  • I am assuming that voice_sponsored_2 is some type of relationship field?

    What Type of field?

    What is the return value set to?

  • It’s a ACF post object set to return a post ID.

  • what is the critical error that you are getting?

  • This reply has been marked as private.
  • This reply has been marked as private.
  • This reply has been marked as private.
  • This reply has been marked as private.
  • Ok Thanks. I thought I already had debugging activated but evidently not.

  • Following on from above – field ‘voice_sponsored_article’ is a post object set to output post id. Modifying the query by hardcoding the post ID works as expected

    function my_query_by_post_id( $query ) {
    	//$sponsored = get_field( 'voice_sponsored_article', 'voice_options' );//this doesn't work
    	$query->set( 'p', '186301' ); //this works
            $query->set( 'p',$voicesponsored_link);// Nope
    add_action( 'elementor/query/voicefilter4', 'my_query_by_post_id' );

    but including the get_field line above seems to create an infinite loop.

    Seems as though I need to build a meta query but unsure how to include the post id.

    $meta_query[] = [
            'key' => 'post_id',
            'value' => get_field( 'voice_sponsored_article') //this is my intention
        $query->set( 'meta_query', $meta_query ); 

    This should be simple enough but I’ve yet to find an answer.

  • If you’re getting an infinite loop then that would mean that your call to get_field() is somehow triggering your action to run again. The cause could be any number of things. Debugging something like this would be complicated. Not something I can explain.

    Sorry, I don’t know enough about the elementor actions to help you.

  • This reply has been marked as private.
  • This reply has been marked as private.
Viewing 18 posts - 1 through 18 (of 18 total)

You must be logged in to reply to this topic.