我们没有针对数据数组的显式过滤器,因此您可以尝试以下两种解决方法:
Approach #1 - As meta data
我们可以通过
wp_get_attachment_metadata
过滤器,但首先我们必须通过
wp_get_attachment_id3_keys
滤器
下面是一个示例:
// Add \'attachment_id\' as an id3 meta key
add_filter( \'wp_get_attachment_id3_keys\', $callback_id3 = function( $fields )
{
$fields[\'attachment_id\'] = \'attachment_id\';
return $fields;
} );
// Add ?attachment_id=123 to the url
add_filter( \'wp_get_attachment_metadata\', $callback_metadata = function ( $data, $post_id )
{
$data[\'attachment_id\'] = (int) $post_id;
return $data;
}, 10, 2 );
// Output from playlist shortcode
$output = wp_playlist_shortcode( $atts, $content );
// Remove our filter callback
remove_filter( \'wp_get_attachment_url\', $callback_metadata );
remove_filter( \'wp_get_attachment_id3_keys\', $callback_id3 );
Approach #2 - As query string
或者,我们可以添加
?attachment_id=123
通过
wp_get_attachment_url
滤器
下面是一个示例:
// Add our filter callback to add ?attachment_id=123 to the url
add_filter( \'wp_get_attachment_url\', $callback = function ( $url, $post_id )
{
return add_query_arg( \'attachment_id\', (int) $post_id, $url );
}, 10, 2 );
// Output from playlist shortcode
$output = wp_playlist_shortcode( $atts, $content );
// Remove our filter callback
remove_filter( \'wp_get_attachment_url\', $callback );
希望有帮助!