0

我发现 wordpress 不会在数据库中保存图像或媒体库图像的链接。只会保存帖子或页面的附加图像。是否有预定义的函数来获取媒体库的所有(原始大小)图像?

我还没有找到任何东西。我会知道如何编写一个自己的递归函数,其中包含许多正则表达式语句,这些语句解析 wordpress 目录的上传文件夹并将路径转换为链接,但如果有预定义的,我更喜欢。;)

4

1 回答 1

0

我不确定您是否理解“依恋”的含义。这是您需要查询图像的帖子类型。例如:

$args = array(
    'post_status'    => 'inherit', 
    'post_type'      => 'attachment', 
    'post_mime_type' => 'image',
    'posts_per_page' => -1,
);

$wp_images = new WP_Query( $args );

$images = array();
foreach ( $wp_images->posts as $image ) {
    // Add each image src to the $images array
    $images[]= wp_get_attachment_url( $image->ID );
}
于 2015-01-13T14:32:01.733 回答