Jump to content

selector to find image description & tags


rushy
 Share

Recommended Posts

Hi

I have a number of pages with images and I'm having a problem selecting on the image descriptions. In the code snippet below, the I added images.description field to my selector and it does work in that I get the expected no. of matches. So findTag gets me a list of images matching the tags in the code, but if I swap that line for the commented line  $match->images->find      it does not work giving 0 results. 

There is findTag for tags but for description there is not a dedicated function, so I should use find. But what selector will give me a list of images matched by image description?

Many thanks.

if($q !== '') {
	$keywords = $sanitizer->selectorValue($q);
	$matches = $pages->find("template=album, title|summary|images.tags|images.description~=$keywords");		
		
	echo "<p>match count: $matches->count</p>";
	foreach($matches as $match){
		echo "<p>{$match->title}</p>";
		$i = $match->images->findTag($keywords);	
		//$i = $match->images->find("template=album, images.description~=$keywords"); GIVES ZERO MATCHES
		$j = count($i);
		echo "<p>No. of image matching: $j</p>";
			
		foreach($i as $img){
			echo "<img src='{$img->url}' alt='{$img->description}'>";
		}
	}			
}

 

Link to comment
Share on other sites

Looks to me (untested) like you shouldn't have images.description but rather description only in your selector, since you're already operating on the images themselves, and images themselves have no template (you have already limited the parent page in your $pages->find call to that).

$match->images->find("description~=$keywords");

should be enough.

  • Like 1
Link to comment
Share on other sites

6 hours ago, BitPoet said:

Looks to me (untested) like you shouldn't have images.description but rather description only in your selector, since you're already operating on the images themselves, and images themselves have no template (you have already limited the parent page in your $pages->find call to that).


$match->images->find("description~=$keywords");

should be enough.

Thank you. That works! But I now realise I need to iterate each album to build a list of tagged images matching. I wonder if there is a sub selector that can do that? Thanks again I can get on with it now 🙂

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...