# Search image caption files

**URL:** <https://forum.getkirby.com/t/search-image-caption-files/8709>\
**Category:** Questions\
**Tags:** v2\
**Created:** [October 5, 2017, 7:33pm UTC](https://forum.getkirby.com/t/search-image-caption-files/8709 "2017-10-05T19:33:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![felixnielsen](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/felixnielsen/32/4668_2.png) [@felixnielsen](https://forum.getkirby.com/u/felixnielsen)\
**Post date:** [October 5, 2017, 7:33pm UTC](https://forum.getkirby.com/t/search-image-caption-files/8709/1 "2017-10-05T19:33:47Z")

</div>

Is there any way to use the search API to search through image caption files (\*.jpg.txt) and returning an array with images whose caption contains the query, alternative return the caption file it self.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [October 5, 2017, 8:09pm UTC](https://forum.getkirby.com/t/search-image-caption-files/8709/2 "2017-10-05T20:09:13Z")

</div>

See this solution:

> [@Search for files](https://forum.getkirby.com/t/search-for-files/480/18):
>
> I tried to implement a custom files methods only to realize that files methods only work with $page-\>files() files objects, while $pages-\>files() returns a collection object. However, you could use the following function, which is a simple port of the pages` search function: function search($files, $query, $params = []) { if(is\_string($params)) { $params = array('fields' =\> str::split($params, '|')); } $defaults = array( 'minlength' =\> 2, 'fields' =\> array(), 'words' …

A filter with a callback function would work here as well.

---

<div class="post-metadata">

**Author:** ![felixnielsen](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/felixnielsen/32/4668_2.png) [@felixnielsen](https://forum.getkirby.com/u/felixnielsen)\
**Post date:** [October 5, 2017, 8:51pm UTC](https://forum.getkirby.com/t/search-image-caption-files/8709/4 "2017-10-05T20:51:32Z")

</div>

Ok, that makes sense. Only thing that is strange now is that my $pages-\>files() is an empty collection…

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [October 5, 2017, 9:03pm UTC](https://forum.getkirby.com/t/search-image-caption-files/8709/5 "2017-10-05T21:03:17Z")

</div>

Do your first level pages contain any images at all? `$pages->files()` will grab all images from all first level pages, i.e. the folders directly in content, not from any children of these pages. Use `page('blog')->children()->files()` to get a collection of all files of all subfolders of the blog page, for example.

---

<div class="post-metadata">

**Author:** ![felixnielsen](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/felixnielsen/32/4668_2.png) [@felixnielsen](https://forum.getkirby.com/u/felixnielsen)\
**Post date:** [October 6, 2017, 8:57am UTC](https://forum.getkirby.com/t/search-image-caption-files/8709/6 "2017-10-06T08:57:06Z")

</div>

awesome, the custom search works and I am now targeting the page correctly (page(‘page-type’)) to search through it’s custom image captions, works like charm.

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:32pm UTC](https://forum.getkirby.com/t/search-image-caption-files/8709/7 "2025-02-06T17:32:02Z")

</div>


