Field image is accepting this type of format for multiple image import:
a:10:{i:0;
a:1:{s:6:"imgurl";s:71:"http://example.com/wp-content/uploads/2015/01/image.jpg";}
i:1;
a:1:{s:6:"imgurl";s:71:"http://example.com/wp-content/uploads/2015/01/image.jpg";}
};
I am trying to find a way to return a json_encode with the above output.
In the process I can't figure out a:10:{}
when converted to array format.
$arr = array('a' => 10, // <-- I have a problem here what to use
array( 'i' => 0, 'a' => 1,
array('s' => [6, 'imgurl'], // <-- I have a problem here what to use
's' => (71,"http://example.com/wp-content/uploads/2015/01/image.jpg")
)
)
);
Am I doing this correctly?
Update:
Sorry I can't response sooner. Since I'm studying how serialize and unserialize works.
A bit of history, I am using WP All Import- Import XML / CSV WordPress plugin to import XML data.
The WP custom post type property
contain a field name _property_slider_image that store an image(s). Standard drag and drop of XML container to that field won't work. Not working as, it's not linking the downloaded images per property.
After checking the mysql database the field accept this type of synthax I mention above. I honestly do not know what it is. Since I only know is json_encode and json_decode. That is why my post mention json_encode.
Thanks to Kiyan. He gave me a hint where to look.
Now I won't be manually mapping each image to each property record.
Result:
Here's my output after a weeks of research.
function sl_output_property_slider(){
$image_url_list = array();
foreach (func_get_args() as $n) {
// get image name
$img_name = get_image_name($n);
// add directory location with the following format
// http://localhost/dev_slrealestate/wp-content/uploads/2015/01/1478_Image.jpeg
$imgurl = 'http://localhost/dev_site/wp-content/uploads/'. date('Y') .'/'. date('m') . '/' . $img_name;
array_push($image_url_list, array('imgurl'=>$imgurl));
}
$serialized_data = serialize($image_url_list);
printf($serialized_data);
}
where function get_image_name($url)
- to return the image name only from original url string.
Sample Usage - short code
[sl_output_property_slider({Images[1]/Image[1]/ImageURL[1]},
{Images[1]/Image[2]/ImageURL[1]},{Images[1]/Image[3]/ImageURL[1]},
{Images[1]/Image[4]/ImageURL[1]},{Images[1]/Image[5]/ImageURL[1]},
{Images[1]/Image[6]/ImageURL[1]},{Images[1]/Image[7]/ImageURL[1]},
{Images[1]/Image[8]/ImageURL[1]},{Images[1]/Image[9]/ImageURL[1]},
{Images[1]/Image[10]/ImageURL[1]}
)
]
See Question&Answers more detail:
os