检查图库的指定帖子内容,如果存在,则返回第一个

原型

get_post_gallery( int|WP_Post $post, bool $html = true )

参数

$post (int|WP_Post) (Optional)  发布ID或WP_Post对象。默认为全球$ post。

$html (bool) (Optional)  是否返回HTML或数据。默认为true。

返回值

(string|array)  从扩展的短代码解析的图库数据和srcs。

源文件

路径:wp-includes/media.php

<?php
...
function get_post_gallery( $post = 0, $html = true ) {
	$galleries = get_post_galleries( $post, $html );
	$gallery = reset( $galleries );
	/**
	 * Filters the first-found post gallery.
	 *
	 * @since 3.6.0
	 *
	 * @param array       $gallery   The first-found post gallery.
	 * @param int|WP_Post $post      Post ID or object.
	 * @param array       $galleries Associative array of all found post galleries.
	 */
	return apply_filters( 'get_post_gallery', $gallery, $post, $galleries );
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/get_post_gallery/