I am trying to add the following array into the meta post table
"a:2:{s:11:"target";a:1:{i:0;a:1:{i:1;a:3:{s:5:"param";s:13:"page_selected";s:8:"operator";s:2:"==";s:5:"value";a:5:{i:3001;s:13:"Service Areas";i:1098;s:19:"Water Slide Rentals";i:672;s:15:"Chairs & Tables";i:205;s:4:"Home";i:1401;s:29:"Bounce House Rental Armada MI";}}}}s:15:"sgpb-conditions";N;}"
I broke down the array as follows
a:2:{ ## ARRAY 1 [3 ELEMENTS]<br>
-->KEY VALUE 1-1<br>
s:11:"target"; a:1:{ ## ARRAY 2 [2 ELEMENTS]<br><br>
-->KEY VALUE 1-2 <br>
i:0; a:1:{ ## ARRAY 3 [2 ELEMENTS]<br><br>
-->KEY VALUE 2-1 <br>
i:1; a:3:{ ## ARRAY 3 [4 ELEMENTS]<br><br>
-->KEY VALUE 3-1 <br>
s:5:"param"; s:13:"page_selected";<br><br>
-->KEY VALUE 3-2 <br>
s:8:"operator"; s:2:"==";<br><br>
-->KEY VALUE 3-3 <br>
s:5:"value"; a:5:{ ## ARRAY 4 [6 ELEMENTS]<br><br>
-->KEY VALUE 4-1 <br>
i:3001; s:13:"Service Areas";<br><br>
-->KEY VALUE 4-2 <br>
i:1098; s:19:"Water Slide Rentals";<br><br>
-->KEY VALUE 4-3 <br>
i:672; s:15:"Chairs & Tables";<br><br>
-->KEY VALUE 4-4 <br>
i:205; s:4:"Home";<br><br>
-->KEY VALUE 4-5 <br>
i:1401; s:29:"Bounce House Rental Armada MI";<br><br>
} <!-- ENDS ARRAY 5 --><br>
} <!-- ENDS ARRAY 4 --><br>
} <!-- ENDS ARRAY 3 --><br>
} <!-- ENDS ARRAY 2 --><br>
s:15:"sgpb-conditions";N;} <!-- ENDS ARRAY 1 --><br>
^^^^^^^^^^^^^^^^^^^^^^^^^^
my question is about First issue I am having is a complete understanding of the array. Not sure how the last values tie into an array. Also, an Array is zero based correct?
Here is the code I have created so far to add the array, which is not creating the array correctly.
"<?php<br>
$poddata = Array(<br>
'sgpb-target',<br>
Array (<br>
1 => Array(<br>
'param' => 'page_selected',<br>
'operator' => '==',<br>
'value' => Array(<br>
3001 => 'Service Areas',<br>
1098 => 'Water Slide Rentals',<br>
672 => 'Chairs & Tables',<br>
1401 => 'Bounce House Rental Armada MI',<br>
676 => 'Mobile Gaming Trucks'<br>
))));<br>
<br>
update_post_meta(6668, 'poddata', $poddata);<br>
?>"
Thanks for any help
I am trying to add the following array into the meta post table
"a:2:{s:11:"target";a:1:{i:0;a:1:{i:1;a:3:{s:5:"param";s:13:"page_selected";s:8:"operator";s:2:"==";s:5:"value";a:5:{i:3001;s:13:"Service Areas";i:1098;s:19:"Water Slide Rentals";i:672;s:15:"Chairs & Tables";i:205;s:4:"Home";i:1401;s:29:"Bounce House Rental Armada MI";}}}}s:15:"sgpb-conditions";N;}"
I broke down the array as follows
a:2:{ ## ARRAY 1 [3 ELEMENTS]<br>
-->KEY VALUE 1-1<br>
s:11:"target"; a:1:{ ## ARRAY 2 [2 ELEMENTS]<br><br>
-->KEY VALUE 1-2 <br>
i:0; a:1:{ ## ARRAY 3 [2 ELEMENTS]<br><br>
-->KEY VALUE 2-1 <br>
i:1; a:3:{ ## ARRAY 3 [4 ELEMENTS]<br><br>
-->KEY VALUE 3-1 <br>
s:5:"param"; s:13:"page_selected";<br><br>
-->KEY VALUE 3-2 <br>
s:8:"operator"; s:2:"==";<br><br>
-->KEY VALUE 3-3 <br>
s:5:"value"; a:5:{ ## ARRAY 4 [6 ELEMENTS]<br><br>
-->KEY VALUE 4-1 <br>
i:3001; s:13:"Service Areas";<br><br>
-->KEY VALUE 4-2 <br>
i:1098; s:19:"Water Slide Rentals";<br><br>
-->KEY VALUE 4-3 <br>
i:672; s:15:"Chairs & Tables";<br><br>
-->KEY VALUE 4-4 <br>
i:205; s:4:"Home";<br><br>
-->KEY VALUE 4-5 <br>
i:1401; s:29:"Bounce House Rental Armada MI";<br><br>
} <!-- ENDS ARRAY 5 --><br>
} <!-- ENDS ARRAY 4 --><br>
} <!-- ENDS ARRAY 3 --><br>
} <!-- ENDS ARRAY 2 --><br>
s:15:"sgpb-conditions";N;} <!-- ENDS ARRAY 1 --><br>
^^^^^^^^^^^^^^^^^^^^^^^^^^
my question is about First issue I am having is a complete understanding of the array. Not sure how the last values tie into an array. Also, an Array is zero based correct?
Here is the code I have created so far to add the array, which is not creating the array correctly.
"<?php<br>
$poddata = Array(<br>
'sgpb-target',<br>
Array (<br>
1 => Array(<br>
'param' => 'page_selected',<br>
'operator' => '==',<br>
'value' => Array(<br>
3001 => 'Service Areas',<br>
1098 => 'Water Slide Rentals',<br>
672 => 'Chairs & Tables',<br>
1401 => 'Bounce House Rental Armada MI',<br>
676 => 'Mobile Gaming Trucks'<br>
))));<br>
<br>
update_post_meta(6668, 'poddata', $poddata);<br>
?>"
Thanks for any help
That original value is a serialised array. If you want to see the original array you can use the unserialize()
function, or a site like https://www.unserialize. The problem is that this isn't working for your Array, because the serialised value is invalid.
The problem is here:
s:11:"target"
"Target" is 6 letters, so this needs to be:
s:6:"target"
This wouldn't happen if you were properly serialising and unserialising in PHP, but it's an easy mistake to make if you're trying to manually edit the data. Generally it's a bad idea to try and edit serialised data by hand.
Anyway, I assume that you want to insert a valid array, so when you fix that issue and then unserialise it, it looks like this:
array(
'target' => array(
0 => array (
1 => array(
'param' => 'page_selected',
'operator' => '==',
'value' => array(
3001 => 'Service Areas',
1098 => 'Water Slide Rentals',
672 => 'Chairs & Tables',
205 => 'Home',
1401 => 'Bounce House Rental Armada MI',
),
),
),
),
'sgpb-conditions' => NULL,
)
<br>
tags in it? – Jacob Peattie Commented Feb 27, 2019 at 10:50