Jump to content

Selectors - has_field


eangulo
 Share

Recommended Posts

Hello,

I passed through a lot of documentation about selectors and a few post in the forum but and I did not find my answer so I'll try here :).

Question: Is there a way to find pages that have a certain field attached to his template ?

Use case:

// Site structure
Products
	Computers
		Computer #1 (has field cached_details)
		Computer #2 (has field cached_details)
	Electronics
		Test #1
	Pet Supplies
		Test #2 (has field cached_details but is empty)

// If I want to get all children of page "products" that contains the field "cached_details" I would do something like this

// $products => PageArray
$results = $products->children("has_field=cached_details");

// or this
$results = $products->children("cached_details!=null");

// Expected: $results would contains [Computer #1, Computer #2, Test #2]

// Instead I have to do this
$results = new PageArray();
foreach($products->children as $child) {
	if ($child->hasField("cached_details") === true) {
		$results->add($child);
	}
}

 

Thank you in advance guys :), 

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...