I have a URL string of images divided by "|" and I would like a php function that reading the string separate the images and divide them with "," to use a wordpress gallery component
I tried to create a php shortcode called get id from string
/* ---------------------------------------------------------------------------
* Shortcode | get_id_from_string
* --------------------------------------------------------------------------- */
add_shortcode('get_id_from_string', 'function_get_id_from_string');
function function_get_id_from_string($atts) {
global $wpdb;
$return_value = '';
$url_array = explode('|', $atts['urls']);
foreach ($url_array as &$url) {
$return_value .= $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $url))[0] . ',';
}
return rtrim($return_value, ',');
}
But it does not work, has anyone already done something like that?
Thanks in advance