Accepts a string of shortcode attributes and returns an associative array of key/value pairs.
// UNABLE TO TEST THIS
// $value = get_post_meta(get_the_ID(), 'some_value', true);
// $sc = $value [ 'item_ticket_tailor' ][ 0 ];
// TEST DATA - assuming the data is a string
$sc="[custom_event id="3106" ][custom_ticket id="3220" show_price="true"]";
// pad some elements for a better parse
$sc = str_replace("[", " [ ", $sc);
$sc = str_replace("]", " ] ", $sc);
// convert the string shortcode to an array
$array = shortcode_parse_atts($sc);
// the last id is the winner, so custom_event id won't show here
// only custom_ticket id
echo $array[ 'id' ]; // 3220
ALTERNATE
$sc="[custom_event id="3106" ][custom_ticket id="3220" show_price="true"]";
// split up the shortcodes
$sc = str_replace("]", " ", $sc);
$sc = str_replace("[", "[", $sc);
$shorts = array_filter(explode('[', $sc));
$custom_event_id = false;
// loop through each one
foreach($shorts as $short) {
// get the individual attributes of the shortcode
$atts = shortcode_parse_atts($short);
// if the first item in the parsed array is `custom_ticket` then get the id
if($atts[ 0 ] === 'custom_ticket') {
$custom_event_id = $atts [ 'id' ];
break;
}
}
echo $custom_event_id; // 3220