So I am getting an array of values from an Advanced Custom Fields repeater field (WordPress)
I’ve named the the array $VideoCategorys
// check if the repeater field has rows of data
if( have_rows('video_headers_list') ):
// Get an array of the items in the list
$VideoCategorys = get_field('video_headers_list');
else :
// no rows found
endif;
What I’d then like to do is take the values from the array and enter them into a foreach loop which will then query posts (working in WordPress) for it’s respective category (the values from the $VideoCategorys are the same as some posts categories)
<?php
//Now I'd like to do a for loop in which I get the value for each array
foreach ($VideoCategorys as $Category) {
query_posts('category_name=$Category');
if ( have_posts() ) : while ( have_posts() ) : the_post();
echo '<h2>'; the_title(); echo '<h2>';
endwhile; endif;
wp_reset_query();
}
?>
<?php wp_reset_query(); ?>
However, I just realized that $VideoCategorys = get_field(‘video_headers_list’);
is giving me a multidimensional array. This is what I get when I do <?php var_dump($VideoCategorys); ?>
MY QUESTION IS How do I get the multidimensional array values (stretching videos, running videos, jumping videos) into an array that I can use in the foreach loop?
This works but it keeps another issue. I’m going to show you the updated code now.
I don’t get why the header with the class VideoSecHeaderH2 is returning the value of ARRAY?
And can someone tell me why I keep getting the scroll bar when I add code on here? How do I avoid that?
//Now I'd like to do a for loop in which I get the value for each array
foreach ($VideoCategorys as $Category) {
$CategoryName = $Category;
$CategoryNameHeader = $Category;
query_posts('category_name=' . $CategoryName['video_category_name']);
if ( have_posts() ) :
echo '<section class="col-xs-12 NoPaddingLeftandRight">';
$CategoryNameHeader = $Category;
echo '<h2 class="VideoSecHeaderH2 col-xs-12 NoPaddingLeftandRight">'; echo $CategoryNameHeader; echo '</h2>';
while ( have_posts() )
: the_post();
echo '<section class="col-lg-6 NoPaddingLeftandRight">';
echo '<h2 class="col-xs-12 NoPaddingLeftandRight"> <a class="col-xs-12 NoPaddingLeftandRight" href='; the_permalink(); echo'>'; the_title(); echo '</a> </h2>';
echo '<div class="embed-container">'; the_field('youtube_video'); echo '</div>';
echo '</section>';
endwhile;
echo '</section>';
else:
endif;
wp_reset_query();
}
?>
<?php wp_reset_query(); ?>
*the code boxing only expands to a limited size to help keep individual posts from getting too wide / long.
While seeing a post of interest without scrollbars would be nice. having a topic with long posts would not be so nice if trying to get to a particular post in the topic.
To not have scrollbars, the code needs to be narrow / short enough to fit in the allotted size.
Which of course is not an ideal solution, but IMHO is a fair compromise.
Well I thought that $Category in this foreach ($VideoCategorys as $Category) is the value within the array. I was thinking that since I assigned $CategoryNameHeader the value of the array that I could output it when I called that variable later. Why can’t I do that? Also how can I call it later?
I used this to get the headers/categories but it still doesn’t make since to me why $Category is an array? Wait. Is it because $Category is an array of another array?