Support

Account

Home Forums ACF PRO Repeater Output: error array to string

Helping

Repeater Output: error array to string

  • Hey there,

    Error I am getting is Array to String
    Currently stumped on this, looked through everything logically related from documentation to threads/posts.

    My goal is to pass this functionality into a shortcode, but my issue lays within what I have programmed. Can I get some input it would greatly be appreciated.

    
    Notice: Array to string conversion in /sites/valet/beauty/web/app/themes/theme57866/inc/acf/api/api-template.php on line 388
    
    Notice: Array to string conversion in /sites/valet/beauty/web/app/themes/theme57866/inc/acf/api/api-value.php on line 42
    

    Screenshots

    Field input:

    Field configurations:

    PHP Code:

    
    /**
     * ACF ShortCode - Events Repeater
     * // Useage [events_list]
     * // Vars
     * // events_repeater - Repeater Group for events
     * // show_event - disable/enable,
     * // event_date_title - date D, M d, Y (format "Full Day, + Full Month + Date Number + Year")
     * // event_description - Description?
     * // event_link - Event link
     *
     * @return string|void
     */
    function events_fn() {
    
    	// checks acf is active
    	if ( ! function_exists( 'have_rows' ) ) :
    		return;
    	endif;
    
    	$output = '';
    
    	// Vars
    	$events_repeater = get_field( 'events_repeater' );
    
    	// check if the repeater field has rows of data
    	if ( have_rows( $events_repeater ) ):
    
    		$output = '<div class="chart-wrapper">';
    
    		// loop through the rows of data
    		while ( have_rows( $events_repeater ) ) : the_row();
    
    			// Vars
    			$show_event        = get_sub_field( 'show_event' );
    			$event_date_title  = get_sub_field( 'event_date_title' );
    			$event_title       = get_sub_field( 'event_title' );
    			$event_description = get_sub_field( 'event_description' );
    			$event_link        = get_sub_field( 'event_link' ); // add .. onclick="window.location.href='http://site.com/someplace-url'"
    
    			// display sub field values
    			if ( $show_event == true ) :
    
    				$output .= '<div class="chart-item"><div class="row">';
    				$output .= '<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8">';
    				$output .= '<strong>' . $event_date_title . ':' . $event_title . '</strong><br>';
    				$output .= $event_description;
    				$output .= '</div>';
    				$output .= '<div class="col-xs-12 col-sm-4 col-md-4 col-lg-4">';
    				$output .= '<button class="btn btn-default btn-lg reservespot" type="button" onclick="window.location.href=\'' . $event_link . '\'"></button><br>';
    				$output .= '</div>';
    				$output .= '</div></div>';
    
    			endif;
    
    		endwhile;
    
    		//closing php loop
    		$output .= '</div>';
    
    	else :
    		// no rows found
    	endif;
    
    	return $output;
    
    }
    
    function register_shortcodes() {
    	add_shortcode( 'events_list', 'events_fn' );
    }
    add_action('init','register_shortcodes');
    
  • This $events_repeater = get_field( 'events_repeater' ); returns a nested array that contains all the rows of a repeater and you’re passing that array back to ACF in have_rows

    this if ( have_rows( $events_repeater ) ): should be if ( have_rows( 'events_repeater' ) ): and this while ( have_rows( $events_repeater ) ) : the_row(); should be while ( have_rows( 'events_repeater' ) ) : the_row();

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Repeater Output: error array to string’ is closed to new replies.