Home › Forums › General Issues › Displaying Value of a Field
Hello all, newbie question.
I have created 4 custom options for portfolio items, which includes uploading an image and then adding a custom title, subtitle, tagline and link. However, when they all return as “Array” instead of the actual value.
I.E.: A portfolio items has the following settings:
Title: Welcome
Subtitle: The Best Place in the World
Tagline: Click Me
Link: https://click.me
However, instead of displaying the correct values, it just all returns as “Array”.
Can someone please help with this, I am getting tired of relying on creating extra divs and putting in this information in the image file (as “Caption”, “Title”, “Description”).
Much thanks will be given!
Exactly how are these fields set up? Are these fields you are getting part of a group field? sub fields of a repeater? Something else?
A group field returns an array. You need to either show the elements of the array or use sub field function. The documentation is here https://www.advancedcustomfields.com/resources/group/
Oh, I misunderstood your question. It is is not as a group, but a text field.
There is no reason that a text field should be returning an array. Please provide some code and additional information on fields you are trying to show.
So sorry for the very late response. Here is my PHP Code
<div class="nk-slider-item <?php echo esc_attr( $active_class ); ?>" data-categories="<?php echo esc_attr( $categories ); ?>" data-background-position="<?php echo esc_attr( $position ); ?>">
<?php
echo '<img
src="' . esc_url( $image['src'] ) . '"
srcset="' . esc_attr( $image_small ? $image_small['src'] : $image['src'] ) . '"
data-srcset="' . esc_attr( $srcset ) . '"
data-sizes="auto"
alt="' . esc_attr( $item['title'] ) . '"
class="lazyload"
style="object-position: ' . esc_attr( $position ) . ';"
title="'?><?php echo $portfolio_title['value'] ?><?php echo'"
subtitle="'?><?php echo $portfolio_subtitle['value'] ?><?php echo'"
tagline="'?><?php echo $portfolio_tagline['value'] ?><?php echo'"
link="'?><?php echo $portfolio_link['value'] ?><?php echo'"
>';
if ( $video_url ) {
echo '<div data-bg-video="' . esc_attr( $video_url ) . '" data-bg-video-size="' . esc_attr( $video_size ? $video_size : '16x9' ) . '"></div>';
}
?>
</div>
And this is the ACP function
if( function_exists('acf_add_local_field_group') ):
// CUSTOM - Add Custom Theme Options
acf_add_local_field_group(array(
'key' => 'group_5d3483d4797b0',
'title' => 'Custom Portfolio Options',
'fields' => array(
array(
'key' => 'field_5d3489ae984d3',
'label' => 'Portfolio Options',
'name' => '',
'type' => 'tab',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'placement' => 'left',
'endpoint' => 0,
),
array(
'key' => 'field_5d3489d2984d4',
'label' => 'Add Titles and Link',
'name' => 'add_titles_and_link',
'type' => 'select',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'choices' => array(
'Yes' => 'Yes',
'No' => 'No',
),
'default_value' => array(
0 => 'No',
),
'allow_null' => 0,
'multiple' => 0,
'ui' => 0,
'return_format' => 'value',
'ajax' => 0,
'placeholder' => '',
),
array(
'key' => 'field_5d348410a77d1',
'label' => 'Title',
'name' => 'portfolio_title',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => array(
array(
array(
'field' => 'field_5d3489d2984d4',
'operator' => '==',
'value' => 'Yes',
),
),
),
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
array(
'key' => 'field_5d348433a77d2',
'label' => 'Subtitle',
'name' => 'portfolio_subtitle',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => array(
array(
array(
'field' => 'field_5d3489d2984d4',
'operator' => '==',
'value' => 'Yes',
),
),
),
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
array(
'key' => 'field_5d34843fa77d3',
'label' => 'Tagline',
'name' => 'portfolio_tagline',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => array(
array(
array(
'field' => 'field_5d3489d2984d4',
'operator' => '==',
'value' => 'Yes',
),
),
),
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
array(
'key' => 'field_5d348a42984d5',
'label' => 'Tagline Link',
'name' => 'tagline_link',
'type' => 'select',
'instructions' => '',
'required' => 0,
'conditional_logic' => array(
array(
array(
'field' => 'field_5d3489d2984d4',
'operator' => '==',
'value' => 'Yes',
),
),
),
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'choices' => array(
'Yes' => 'Yes',
'No' => 'No',
),
'default_value' => array(
0 => 'No',
),
'allow_null' => 0,
'multiple' => 0,
'ui' => 0,
'return_format' => 'value',
'ajax' => 0,
'placeholder' => '',
),
array(
'key' => 'field_5d34844ea77d4',
'label' => 'Link',
'name' => 'portfolio_link',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => array(
array(
array(
'field' => 'field_5d348a42984d5',
'operator' => '==',
'value' => 'Yes',
),
),
),
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'portfolio',
),
),
),
'menu_order' => 10,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => true,
'description' => '',
));
acf_add_local_field_group(array(
'key' => 'group_5d3484b7e9e69',
'title' => 'Custom Theme Options',
'fields' => array(
array(
'key' => 'field_5d3487527b146',
'label' => 'Translate Options',
'name' => '',
'type' => 'tab',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'placement' => 'left',
'endpoint' => 0,
),
array(
'key' => 'field_5d3484efa4eca',
'label' => 'Translatable',
'name' => 'translatable',
'type' => 'select',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'choices' => array(
'Yes' => 'Yes',
'No' => 'No',
),
'default_value' => array(
0 => 'No',
),
'allow_null' => 0,
'multiple' => 0,
'ui' => 0,
'return_format' => 'value',
'ajax' => 0,
'placeholder' => '',
),
array(
'key' => 'field_5d3489189d192',
'label' => 'English Page',
'name' => 'english_page',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => array(
array(
array(
'field' => 'field_5d3484efa4eca',
'operator' => '==',
'value' => 'Yes',
),
),
),
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
array(
'key' => 'field_5d34892d9d193',
'label' => 'French Page',
'name' => 'french_page',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => array(
array(
array(
'field' => 'field_5d3484efa4eca',
'operator' => '==',
'value' => 'Yes',
),
),
),
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
array(
'key' => 'field_5d34893c9d194',
'label' => 'Spanish Page',
'name' => 'spanish_page',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => array(
array(
array(
'field' => 'field_5d3484efa4eca',
'operator' => '==',
'value' => 'Yes',
),
),
),
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
array(
'key' => 'field_5d34894c9d195',
'label' => 'German Page',
'name' => 'german_page',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => array(
array(
array(
'field' => 'field_5d3484efa4eca',
'operator' => '==',
'value' => 'Yes',
),
),
),
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'page',
),
),
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'post',
),
),
),
'menu_order' => 20,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => true,
'description' => '',
));
endif;
I have been able to echo successfully before, but I think this code is incorrect.
Wow, I feel so dumb. Just figure out my problem. LOCATION!!!!!!
foreach ( $portfolio_items as $item ) {
$image = nk_get_attachment( $item['thumbnail'], 'nk_1920x1080' );
$image_small = nk_get_attachment( $item['thumbnail'], 'nk_300x300' );
$pTitle = get_field_object('portfolio_title', $item['id']);
$pSubtitle = get_field_object('portfolio_subtitle', $item['id']);
$pTagline = get_field_object('portfolio_tagline', $item['id']);
$pLink = get_field_object('portfolio_link', $item['id']);
if ( $image || $image_small ) {
$active_class = $active_slide == $item['id'] ? 'active' : '';
$position_x = nk_get_option( 'background_x_position', 50, true, $item['id'] );
$position_y = nk_get_option( 'background_y_position', 50, true, $item['id'] );
$position = (int) $position_x . '% ' . (int) $position_y . '%';
// prepare video
$video_type = nk_get_option( 'video_type', 'disable', true, $item['id'] );
$video_url = '';
$video_size = nk_get_option( 'video_size', '', true, $item['id'] );
if ( $video_type === 'local' ) {
$mp4 = nk_get_option( 'video_mp4', '', true, $item['id'] );
$webm = nk_get_option( 'video_webm', '', true, $item['id'] );
$ogv = nk_get_option( 'video_ogv', '', true, $item['id'] );
if ( $mp4 && is_array( $mp4 ) ) {
$video_url .= 'mp4:' . esc_url( $mp4['url'] );
}
if ( $webm && is_array( $webm ) ) {
$video_url .= ( strlen( $video_url ) ? ',' : '' ) . 'webm:' . esc_url( $webm['url'] );
}
if ( $ogv && is_array( $ogv ) ) {
$video_url .= ( strlen( $video_url ) ? ',' : '' ) . 'ogv:' . esc_url( $ogv['url'] );
}
} else if ( $video_type === 'yt_vm' ) {
$video_url = nk_get_option( 'video_url', '', true, $item['id'] );
}
$categories = '';
if ( $item['categories'] && count( $item['categories'] ) > 0 ) {
foreach ( $item['categories'] as $k => $cat ) {
$categories .= ( $k > 0 ? '|' : '' ) . $cat->name;
}
}
$srcset = wp_get_attachment_image_srcset( $item['thumbnail'], 'nk_1920x1080' );
?>
<div class="nk-slider-item <?php echo esc_attr( $active_class ); ?>" data-categories="<?php echo esc_attr( $categories ); ?>" data-background-position="<?php echo esc_attr( $position ); ?>">
<?php
echo '<img
src="' . esc_url( $image['src'] ) . '"
srcset="' . esc_attr( $image_small ? $image_small['src'] : $image['src'] ) . '"
data-srcset="' . esc_attr( $srcset ) . '"
data-sizes="auto"
alt="' . esc_attr( $item['title'] ) . '"
class="lazyload"
style="object-position: ' . esc_attr( $position ) . ';"
title="'?><?php echo $pTitle['value'] ?><?php echo'"
subtitle="'?><?php echo $pSubtitle['value'] ?><?php echo'"
tagline="'?><?php echo $pTagline['value'] ?><?php echo'"
link="'?><?php echo $pLink['value'] ?><?php echo'"
>';
if ( $video_url ) {
echo '<div data-bg-video="' . esc_attr( $video_url ) . '" data-bg-video-size="' . esc_attr( $video_size ? $video_size : '16x9' ) . '"></div>';
}
?>
</div>
<?php
I was placing the acf code in the wrong area. Although, if you have a better way to code, that will be a big help too. I know, my code is sloppy. 🙁
The topic ‘Displaying Value of a Field’ is closed to new replies.
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.