我花了一段时间才找到一个适合我的解决方案,但由于我所寻找的只是与某个属性相关联的附件id的分隔列表,如exclude
或hide
, 这对我很有用:
# Grab the list of "hide" attribute
$regex_pattern = get_shortcode_regex();
preg_match (\'/\'.$regex_pattern.\'/s\', $post->post_content, $regex_matches);
if ($regex_matches[2] == \'gallery\') :
$attribureStr = str_replace (" ", "&", trim ($regex_matches[3]));
$attribureStr = str_replace (\'"\', \'\', $attribureStr);
// Parse the attributes
$defaults = array (
\'hide\' => \'1\',
);
$attributes = wp_parse_args ($attribureStr, $defaults);
if (isset ($attributes["hide"])) :
$excludeID = get_post_thumbnail_id() . \',\' . $attributes["hide"];
else :
$excludeID = get_post_thumbnail_id();
endif;
endif;