I have this shortcode in my page content in Wordpress. I need to get the value of "layout" and the value from "slug"
So I need the values: listing & aircraft extracted from the string
I am looking for the lowest possible hit to performance. I am trying to get these values from the save_post hook so I don't have access to the normal shortcode $atts parameter.
'[vc_row][vc_column width="2/3"]
[cpt_categories layout="listing" view="grid" items_per_row="4" orderby="title" order="ASC" slug="aircraft"]
[/vc_column][vc_column width="1/3"][/vc_column][/vc_row]'
When using the native WP function shortcode_parse_atts I get close but there are some issues:
$atts = shortcode_parse_atts($post->post_content);
var_dump($atts);
array
0 => '[vc_row][vc_column'
1 => 'width="2/3"][cpt_categories'
'layout' => 'listing'
'view' => 'grid'
'items_per_row' => '4'
'orderby' => 'title'
'order' => 'ASC'
2 => 'slug="aircraft"][/vc_column][vc_column'
3 => 'width="1/3"][/vc_column][/vc_row]'
If those two values are literally all you need, then Regex could be a reasonable solution here. (just be careful about the whole "hammer and nails" thing with Regex and HTML)
Match group 1 in layout="([^"]*)" will get you the listing value.
Match group 1 in slug="([^"]*)" will get you the aircraft value.
They both work on your example string (as tested at https://regex101.com/).