I am currently trying to create a drop down feature with the repeater
custom field input. This may or may not be the right custom field to be used but it seems like it is given the other offered options. So, this is what my custom field looks like on the admin panel:
It is very simple what I am trying to do. I am trying to display the first three options of this list. I then want to add a SEE MORE
button that the user can click and it will show all subsequent updates
. Example:
I am using bootstrap
for handling the accordion feature
. The issue that I am having is splitting the data appropriately. Getting the first three rows into the container displaying on the page... and the rest into the bootstrap accordion
container. My thought was to approach this by creating two arrays. Slicing the first three rows into the first array and then slicing from row four on into the second array. The only problem I am having is handling the data that comes in from the backend. It is very confusing and I may be going about this in a wrong way.
The first thing I noticed was that each row from the admin panel comes in as separate arrays when using the get_row()
function. NOT separate arrays wrapped in array:
How it comes in: [] [] [] []
How it does NOT come in: [[], [], [], []]
This obviously means I cannot perform php array functionality on these as a group because they are not in an array. So I decided to put them in an array array_push($new_array, $rows)
. This KINDA works as I receive an output of:
Array (
[0] => Array (
[field_598a36a3cea71] => July 5, 2017
[field_598a36bdcea72] => ONE
)
[1] => July 5, 2017
[2] => ONE
[3] => Array (
[field_598a36a3cea71] => July 6, 2017
[field_598a36bdcea72] => TWO
)
[4] => July 6, 2017
[5] => TWO
[6] => Array (
[field_598a36a3cea71] => July 7, 2017
[field_598a36bdcea72] => THREE
)
[7] => July 7, 2017
[8] => THREE
[9] => Array (
[field_598a36a3cea71] => July 8, 2017
[field_598a36bdcea72] => FOUR
)
[10] => July 8, 2017
[11] => FOUR )
As you will see, every third Array()
is a complete array, but it is also returning every single value that exists... So if I do print_r(count($new_array))
this is going to come back as 12 arrays in my $new_array
. Four being each row coupled, the next eight being every single item within my rows. Here is the code that I am playing with right now:
<?php if(have_rows('updates_list')): ?>
<?php $new_array = array() ?>
<?php while(have_rows('updates_list')): the_row(); ?>
<?php $rows = get_row(); ?>
<?php array_push($new_array, $rows) ?>
<?php endwhile; ?>
<?php print_r($new_array) ?>
<?php endif; ?>
Quite frankly, because I am so new I do not know if I am on the right path, using the right custom field, writing syntactically correct my php... So any ideas, help, suggestions on how I can achieve this I would greatly appreciate it. I will tentatively be watching any questions and comments that are posted, so expect a relatively quick response from myself. Thank you in advance to anyone who helps or assists in any way.
get_row()
coupled withthe_row()
was creating the issue. I needed to return an array of each row as an array.get_field()
is the function for this.