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();
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
🚀 This week’s session of ACF Chat Fridays dips into the preliminary results of our first ever user survey. Don’t miss it! https://t.co/3UtvQbDwNm pic.twitter.com/kMwhaJTkZc
— Advanced Custom Fields (@wp_acf) May 9, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.