Thank you for pointing me in the right direction! I was able to add those into an array, although within an extra associate array, with the below and just need to figure out how to add the similar indices, and add the counts and details.
if( have_rows('flowers_count_list') ):
// Loop through rows.
while( have_rows('flowers_count_list') ) : the_row();
$featured_posts = get_sub_field('flowers');
if( $featured_posts ): ?>
<?php foreach( $featured_posts as $post ):
// Setup this post for WP functions (variable must be named $post).
setup_postdata($post); ?>
<?php /*
echo get_the_title( $post->ID );
echo '( ';
the_sub_field('flowers_count');
echo ' )';
*/
$flowers_count_list_full_array[] = [
'name'=> get_the_title( $post->ID ),
'count'=>get_sub_field('flowers_count'),
'details'=> get_the_title().' ('.get_sub_field('flowers_count').')',
];
?>
<?php endforeach; ?>
<?php
// Reset the global post object so that the rest of the page works correctly.
wp_reset_postdata();
endif;
// End loop.
endwhile;
// No value.
else :
// Do something...
endif;
// Check rows exists.
if( have_rows('hard_goods_count_list') ):
//echo '<h3>Hard Goods List:</h3>';
// Loop through rows.
while( have_rows('hard_goods_count_list') ) : the_row();
$featured_posts = get_sub_field('hard_goods');
if( $featured_posts ): /*?>
<ul>
<?php foreach( $featured_posts as $post ):
// Setup this post for WP functions (variable must be named $post).
setup_postdata($post); ?>
<li>
<?php
echo get_the_title( $post->ID );
echo '( ';
the_sub_field('hard_goods_count');
echo ' )';
?>
</li>
<?php endforeach; ?>
</ul>
<?php*/
// Reset the global post object so that the rest of the page works correctly.
wp_reset_postdata();
endif;
// End loop.
endwhile;
// No value.
else :
// Do something...
endif;
echo '</div>';
endwhile;
echo '</div>';
echo '<h3>Flowers List:</h3>';
echo 'Filled Array!: <br/>';
print_r($flowers_count_list_full_array);
echo '<br/>Combined Array!: <br/>';
$combined_flowers_count_list_full_array = $flowers_count_list_full_array;
var_dump(array_merge($flowers_count_list_full_array));
wp_reset_postdata();
else :
echo 'No posts found';
endif;
die();
}
Thanks for the image get_sub_field change!
I looked through everything else and it seems in order. It’s really bugging me as I’ve focused a few mornings on just this.
Edit: Further making this more strange is that I just clicked a post and a page and the slider shows but on the homepage and archive page it doesn’t!
Edit 2: I thought back about this after the first edit and I found the problem. I had code in the functions.php of my theme that was conflicting with ACF.
Here is the code in question that I removed and then everything started working fine.
// Adding custom post types to homepage
add_filter( 'pre_get_posts', 'my_get_posts' );
function my_get_posts( $query ) {
if ( is_home() && false == $query->query_vars['suppress_filters'] )
$query->set( 'post_type', array( 'post', 'quote', 'attachment', 'status', 'audio', 'chat', 'video' ) );
return $query;
}
//CPT on Archives
function add_custom_types_to_archives( $query ) {
if (! is_post_type_archive() ) {
if( is_archive() && empty( $query->query_vars['suppress_filters'] ) ) {
/*// Get all your post types
$post_types = get_post_types();*/
$post_types = array('post','movie');
$query->set( 'post_type', $post_types );
return $query;
}
}
}
add_filter( 'pre_get_posts', 'add_custom_types_to_archives' );
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.