尝试此操作,并验证直接查询时附件是否正确返回:
// helper function to return first regex match
function get_match( $regex, $content ) {
preg_match($regex, $content, $matches);
return $matches[1];
}
// Extract the shortcode arguments from the $post
$shortcode_args = shortcode_parse_atts(get_match(\'/\\[gallery\\s(.*)\\]/isU\', $post->post_content));
// get the attachments specified in the "ids" shortcode argument
$attachments = get_posts(
array(
\'include\' => $shortcode_args["ids"],
\'post_status\' => \'inherit\',
\'post_type\' => \'attachment\',
\'post_mime_type\' => \'image\',
\'order\' => \'menu_order ID\',
\'orderby\' => \'post__in\', //this forces the order to be based on the order of the "include" param
)
);
echo \'gallery count:\' . count( $attachments );
如果该计数正确,则库短代码应正确返回。让我知道会有什么回报。